77Vetter
77Vetter

Reputation: 269

Azure Search Order

We have a search screen where the user can enter a phrase and then search Azure for rows that contain the phrase or any words of the phrase. They want to see the results ordered by the rows that contain the entire phrase first followed by rows that contain any or all of the words that make up the phrase.

This is my search string that I am testing with in Search Explorer in portal:

search="\"cause and healthcare\"" cause and healthcare&queryType=full&searchMode=any

So in this example they want to see rows that contain the phrase "cause and healthcare" first and then any rows that contain any/all of "cause" "and" "healthcare"

When I run the above query in the Search Explorer in Azure portal, it "seems" to return the rows with the entire phrase first followed by the others in no particular order. But I am getting a different order when I run from from dotNet:

       SearchParameters parameters = new SearchParameters()
        {
            Filter = newFilter,
            QueryType =  QueryType.Full,
            Top = recordsPerPage,
            Skip = skip,
            SearchMode = SearchMode.Any,
            IncludeTotalResultCount = true
        };
        query = string.Format("\"{0}\" {0}", query);

I have looked at term boosting in the Search Explorer by putting ^2, ^4 etc. within the search string but that doesn't seem to have any impact.

Ideally I would like the rows that contain the entire phrase returned first, followed by rows that contain the first word, followed by rows that contain second word etc.

How can I change my code to ensure the rows are returned in the specified order?

Upvotes: 0

Views: 114

Answers (1)

Pablo Castro
Pablo Castro

Reputation: 1691

If you're using full Lucene queries (which I see you already enabled), you can boost the phrase match much higher than the other matches to achieve the effect you described.

Your query rewritten this way would be:

search=("cause and healthcare")^100 (cause and healthcare)&queryType=full&searchMode=any

Note that in your example you're escaping quotes, you don't need to escape them (unless the host language needs it, as you correctly did it in the C# example, but at the URL level you shouldn't do that as it ends up meaning something else). That's probably what's causing the difference between .NET client and query explorer, and what caused the boosting operator not to work in your tests.

If you want to do whole-phrase followed by first word followed by second word, etc., then use boosts to force the order, e.g.:

("phrase")^100 firstword^25 secondword^10 ...

Upvotes: 0

Related Questions