Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to use Microsoft.Azure.Search SearchContinuationToken

Can someone point me in the right direction of how to implement this?

So far I can query my index and get a response

SearchIndexClient indexClient = service.Indexes.GetClient(indexName);
 SearchParameters sp = new SearchParameters()
        {
            Facets = new string[] { "Brand", "Price,values:10|25|100|500|1000|2500" },
            Filter = AzureUtils.BuildFilter(brand, priceFrom, priceTo),
            OrderBy = new string[] { "" },
            IncludeTotalResultCount = true,
            Top = 9,
            SearchMode = SearchMode.Any
        };
        DocumentSearchResponse<MyClass> response = response = indexClient.Documents.Search<MyClass>(searchText, sp);

When the result comes back the response.ContinuationToken is null

How can I get my index to return a value for the response.ContinuationToken property.

Also, how do I can implement this to fetch the next 9 results?

Thanks

like image 314
robsta Avatar asked Nov 20 '15 12:11

robsta


People also ask

How do I do Azure Cognitive Search?

Create a search service in the Azure portal. Start with Import data wizard. Choose a built-in sample or a supported data source to create, load, and query an index in minutes. Finish with Search Explorer, using a portal client to query the search index you just created.

How do I connect to Azure search?

Under Settings on the left navigation pane, select Networking. On the Shared Private Access tab, select + Add Shared Private Access. On the blade that opens on the right, select either Connect to an Azure resource in my directory or Connect to an Azure resource by resource ID or alias.

How do I search Azure index?

Query using Search explorer The tool supports simple query syntax and full Lucene query parser. Select Search explorer on the command bar. From Index, choose "hotels-sample-index". In the search bar, paste in a query string from the examples below and select Search.


2 Answers

I found my answer here - Link

This property will be null unless you request more results than the page size. This can happen either when you do not specify Top and there are more than 50 results (default page size is 50), or when you specify a value greater than 1000 for Top and there are more than 1000 results (maximum page size is 1000). In either case, you can pass the value of this property to the ContinueSearchAsync method to retrieve the next page of results.

I hope that it helps someone else if they get stuck like me

like image 88
robsta Avatar answered Oct 04 '22 19:10

robsta


TL;DR version: The safest assumption is that the presence or absence of a continuation token in a search response is completely out of your control.

The SearchContinuationToken is not meant for paging of results. That's what SearchParameters.Top and SearchParameters.Skip are for. Instead, you can think of the continuation token as a mechanism to resume a search that couldn't be completed in a single request for potentially arbitrary reasons. The docs on MSDN mention page size as the reason, but this should not be understood to be part of the contract of ContinueSearch. In principle there could be other reasons why Azure Search hands back a continuation token. No matter the reason, if you want to write a robust client you should be prepared to handle continuation tokens, regardless of Top, your result count, or any other factor.

like image 40
Bruce Johnston Avatar answered Oct 04 '22 21:10

Bruce Johnston