5

We would like to know, whether Azure Search makes possible undermentioned scenario.

Let us have an Azure Search index with three columns:

1.  Id [Edm.String]
2.  Tags [Collection(Edm.String)]
3.  MaxScore [Edm.Int32]

The index contains the following two entries:

Id  Tags                MaxScore
1   Paris,London,Rome   30
2   Paris               10

We have also a scoring profile and a scoring function of type Tag (Sum, Linear) which evaluate every tag by 10 points (boost = 10).

We want to search the records with tags "Paris, London" in this index and sort it according to the percentage of compliance, while 100% is the value in column MaxScore.

The problem is that by default Azure Search sorts records by score. So the results are following:

Id  Tags                MaxScore    Score     %
1   Paris,London,Rome   30          20        67%
2   Paris               10          10        100%

But we need to sort the records in descending order by the [%] column. It would be enough to makes possible Azure Search sorts records by expression. It would be something like $orderby=score*(100/MaxScore) in our case. However this is not currently possible.

Thank you.

TheZ
  • 3,663
  • 19
  • 34
Keeble
  • 66
  • 1
  • 6

2 Answers2

1

Azure Search does not support this scenario at this time. Please consider adding an item to our User Voice site for supporting expressions in $orderby. Also, please vote on this suggestion to support explicitly sorting by score in $orderby.

Bruce Johnston
  • 8,344
  • 3
  • 32
  • 42
1

I did sorting based on date columns, hope this might be helpful. Here I am using .NET SDK if required the same options available in REST API also.

public async Task<DocumentSearchResult<Documents>> FileSearchResultsAsync(SearchRequest searchRequest)
    {
        try
        {
            SearchParameters sp = new SearchParameters()
            {
                SearchMode = SearchMode.Any,
                Facets = new List<String>() { "state,count:25,sort:value",
                                             "fileType,count:25,sort:value"
                                            },
                Top = 10,
                Skip = searchRequest.PageNumber > 1 ? searchRequest.PageNumber * 10 : 0,
                OrderBy = searchRequest.SortOrder == SortOrder.Recent ? new List<string> { "pubDate desc" } : new List<string> { "" },
                IncludeTotalResultCount = true,
                Select = new List<string>
                {
                    "fileName",
                    "state",
                    "fileType",
                    "pubDate"
                },
                Filter = BuildFacetFilter(searchRequest)
            };

            return await searchConfig.IndexClient.Documents.SearchAsync<Documents>(searchRequest.SearchQuery, sp);
        }
        catch (Exception)
        {
            throw;
        }
    }
Muni Chittem
  • 988
  • 9
  • 17