Numeric range search or numerical search allows you to search documents for integer numbers in the range from 0 to 9223372036854775807 (Int64.MaxValue). Please note that a number in the text must not be separated by spaces; otherwise, it is treated as several numbers. A search query of this type is specified as follows:
number ~~ number
The example below demonstrates the numeric range search in text and object forms.
C#
stringindexFolder=@"c:\MyIndex\";stringdocumentsFolder=@"c:\MyDocuments\";// Creating an index in the specified folderIndexindex=newIndex(indexFolder);// Indexing documents from the specified folderindex.Add(documentsFolder);// Search with text querySearchResultresult1=index.Search("500 ~~ 600");// Search with object querySearchQueryquery2=SearchQuery.CreateNumericRangeQuery(500,600);SearchResultresult2=index.Search(query2);
Since version 26.10, numeric range search uses as many threads as there are processor cores by default. Therefore, the order of the found numbers in the search result may differ from run to run. To get the same order every time, set the SearchThreads index setting to NumberOfThreads.One.
More resources
GitHub examples
You may easily run the code from documentation articles and see the features in action in our GitHub examples: