Text search in network

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.

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 following code example demonstrates performing a full-text search on the search network.

Searcher searcher = node.getSearcher();

SearchOptions options = new SearchOptions();
options.setChunkSearch(true);
options.setUseSynonymSearch(useSynonymSearch);
int totalOccurrences = 0;
ArrayList<NetworkFoundDocument> documents = new ArrayList<NetworkFoundDocument>();

NetworkSearchResult result;
if (isObjectForm) {
    SearchQuery query = SearchQuery.createWordQuery(word);
    System.out.println();
    System.out.println("First time search in object form for: " + query);
    result = searcher.searchFirst(query, options);
} else {
    String query = word;
    System.out.println();
    System.out.println("First time search in text form for: " + query);
    result = searcher.searchFirst(query, options);
}

addDocsFromResult(documents, result);
totalOccurrences += result.getOccurrenceCount();
traceResult(result);

while (result.getNextChunkSearchToken() != null) {
    System.out.println();
    System.out.println("Next time search for: " + word);

    result = searcher.searchNext(result.getNextChunkSearchToken());

    addDocsFromResult(documents, result);
    totalOccurrences += result.getOccurrenceCount();
    traceResult(result);
}

System.out.println();
System.out.println("Total occurrences: " + totalOccurrences);

More information about search queries can be found in the article Queries in text and object form.

More resources

GitHub examples

You may easily run the code from documentation articles and see the features in action in our GitHub examples:

Free online document search App

Along with full featured .NET library we provide simple, but powerful free Apps.

You are welcome to search over your PDF, DOC, DOCX, PPT, PPTX, XLS, XLSX and more with our free online Free Online Document Search App.