To run a text search, use the SearchFirst method of the Searcher class. This method returns the first portion of results.
To continue the search, the SearchNext method is used, returning the second and subsequent portions of results. Continue the search while the NextChunkSearchToken property of the result is not null.
Text and object forms of the search query are supported when appropriate overloads of the SearchFirst method are used. The options for a network search are the same as those for a single index search. The search network supports only search by chunks: the IsChunkSearch option must be set to true; otherwise, the SearchFirst method throws ArgumentException.
Since version 26.11, the SearchFirst method observes the Cancellation of the search options: when the cancellation is requested, the method returns at once with an empty result whose warnings are “Operation cancelled.” and which has no next chunk, as a search of an index does. A shard that has got the request completes the search, and its result is ignored. The SearchNext method does not observe the cancellation of the options of the first search.
Each portion of results is returned as a NetworkSearchResult object, which has the following members:
NodeIndex — the index of the node from which the result was received;
NextChunkSearchToken — the token for continuing the search, or null if the search is complete.
A found document is represented by the NetworkFoundDocument class, which contains the FoundDocument object, as in a single index search, and the index of the shard where the document was found (ShardIndex property).
Note
Since version 26.11, a NetworkSearchResult applies the limit of the evaluation mode as a search result of an index does: only the first 10 found documents of a result can be retrieved, the GetFoundDocument method throws LicenseRestrictionException for a document number of 10 or greater, and an enumeration of the result, such as the AddRange call in the example below, throws it after the first 10 documents. See Evaluation limitations and licensing.
The examples on this page use the master node of a running search network. The following code creates and starts the master node as described on the Search network deployment page; the slave nodes must be started beforehand.
C#
stringbasePath=@"c:\SearchNetwork\";intbasePort=49100;// Loading the search network configuration from a fileConfigurationconfiguration=Configuration.Load(basePath+"Configuration.xml");// Creating, configuring and starting the master node; the timeouts are specified in millisecondsSearchNetworkNodenode=SearchNetworkNode.CreateMasterNode(0,basePath+"Node0",newTcpSettings(basePort,3000,3000,3000,1000),newFileLogger(basePath+"Log.txt",4.0),configuration);node.ConfigureAllNodes();node.Start();
The following code example, which continues the previous one, demonstrates performing a full-text search on the search network.
C#
stringword="einstein";booluseSynonymSearch=true;Searchersearcher=node.Searcher;SearchQueryquery=SearchQuery.CreateWordQuery(word);Console.WriteLine();Console.WriteLine("First time search for: "+query);SearchOptionsoptions=newSearchOptions();options.IsChunkSearch=true;options.UseSynonymSearch=useSynonymSearch;inttotalOccurrences=0;List<NetworkFoundDocument>documents=newList<NetworkFoundDocument>();NetworkSearchResultresult=searcher.SearchFirst(query,options);documents.AddRange(result);totalOccurrences+=result.OccurrenceCount;Console.WriteLine("Documents found (node "+result.NodeIndex+"): "+result.DocumentCount);while(result.NextChunkSearchToken!=null){Console.WriteLine();Console.WriteLine("Next time search for: "+query);result=searcher.SearchNext(result.NextChunkSearchToken);documents.AddRange(result);totalOccurrences+=result.OccurrenceCount;Console.WriteLine("Documents found (node "+result.NodeIndex+"): "+result.DocumentCount);}Console.WriteLine();Console.WriteLine("Total occurrences: "+totalOccurrences);for(inti=0;i<documents.Count;i++){NetworkFoundDocumentdocument=documents[i];Console.WriteLine(document.ShardIndex+": "+document.FoundDocument.DocumentInfo.FilePath+" ("+document.FoundDocument.OccurrenceCount+" occurrences)");}