The GroupDocs.Search API provides the ability to perform search by chunks. This means that in one call to the search method of the Index class, only in one index segment search is performed. This feature becomes relevant when searching in large indexes containing tens and hundreds of thousands of documents.
When performing search by chunks, the search method is first called with the chunk search flag set to true via setChunkSearch method of the SearchOptions class. And then the search in each subsequent segment is performed using the searchNext method with passing ChunkSearchToken of the next chunk as an argument.
The following example demonstrates the search by chunks.
StringindexFolder="c:\\MyIndex\\";StringdocumentsFolder="c:\\MyDocuments\\";Stringquery="Einstein";// Creating an index in the specified folder
Indexindex=newIndex(indexFolder);// Indexing documents from the specified folder
index.add(documentsFolder);// Creating a search options instance
SearchOptionsoptions=newSearchOptions();options.setChunkSearch(true);// Enabling the search by chunks
// Starting the search by chunks
SearchResultresult=index.search(query,options);System.out.println("Document count: "+result.getDocumentCount());System.out.println("Occurrence count: "+result.getOccurrenceCount());// Continuing the search by chunks
while(result.getNextChunkSearchToken()!=null){result=index.searchNext(result.getNextChunkSearchToken());System.out.println("Document count: "+result.getDocumentCount());System.out.println("Occurrence count: "+result.getOccurrenceCount());}
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: