Sometimes, we have a lot of different formatted documents. We create index then perform search and API shows hits from all the indexed documents. Ever thought to get search results from desired documents only?
Let’s dig it further. Suppose, you have multiple TXT, XLSX and DOCX documents. What if you want to search a word or text only in TXT and DOCX files with specific word occurrence in file names? We’ve now improved ISearchDocumentFilter interface for such a purpose in GroupDocs.Search. This interface represents search document filter and it uses SearchDocumentFilter class for creation of a filter instances.
Let’s now understand this with a use-case.
C#
//For complete examples and data files, please go to https://github.com/groupdocs-search/GroupDocs.Search-for-.NET | |
string indexFolder = @"c:\MyIndex"; | |
string documentFolder = @"c:\MyDocuments"; | |
//Creating index | |
Index index = new Index(indexFolder); | |
//Adding documents to index | |
index.AddToIndex(documentFolder); | |
//Configuring document filter | |
//filter3 will only accept TXT and DOCX documents with text 'task' in file names | |
SearchParameters parameters = new SearchParameters(); | |
ISearchDocumentFilter filter1 = SearchDocumentFilter.CreateFileExtension(".txt", ".docx"); | |
ISearchDocumentFilter filter2 = SearchDocumentFilter.CreateFileNameRegularExpression("task"); | |
ISearchDocumentFilter filter3 = SearchDocumentFilter.CreateConjunction(filter1, filter2); | |
parameters.SearchDocumentFilter = filter3; | |
//Searching | |
SearchResults results = index.Search("hobbit", parameters); |
//For complete examples and data files, please go to https://github.com/groupdocs-search/GroupDocs.Search-for-Java | |
String indexFolder = "c:\\MyIndex"; | |
String documentFolder = "c:\\MyDocuments"; | |
//Creating index | |
Index index = new Index(indexFolder); | |
//Adding documents to index | |
index.addToIndex(documentFolder); | |
//Configuring document filter | |
//Filter filter3 will only accept TXT and DOC documents with text 'Tolkien' in file names | |
SearchParameters parameters = new SearchParameters(); | |
ISearchDocumentFilter filter1 = SearchDocumentFilter.createFileExtension(".txt", ".doc"); | |
ISearchDocumentFilter filter2 = SearchDocumentFilter.createFileNameRegularExpression("task"); | |
ISearchDocumentFilter filter3 = SearchDocumentFilter.createConjunction(filter1, filter2); | |
parameters.setSearchDocumentFilter(filter3); | |
//Searching | |
SearchResults results = index.search("hobbit", parameters); |
What we did in this example? We initiated a request to search occurrence of a word hobbit in all the TXT and DOCX files with word task in their file names. In this snippet, you can see a method CreateConjuction. It creates logical conjunction (logical and) of the specified filters.
Settings for Log Functionality
This improvement allows to set up log file name and maximum log file size. Below are the public API changes.
Following class has been added to GroupDocs.Search namespace and com.groupdocs.search package:
- LogSettings
Following properties are added to GroupDocs.Search.LogSettings and com.groupdocs.search.LogSettings class: C#
- string FileName
- double MaxSize
Java
- String getFileName()
- void setFileName(String value)
- double getMaxSize()
- void setMaxSize(double value)
Below properties are added to GroupDocs.Search.Index and com.groupdocs.search.Index classes respectively:
- LogSettings LogSettings
- LogSettings getLogSettings()
Let’s go through the implementation:
C#
//For complete examples and data files, please go to https://github.com/groupdocs-search/GroupDocs.Search-for-.NET | |
string indexFolder = @"c:\MyIndex"; | |
string documentFolder = @"c:\MyDocuments"; | |
//Creating index | |
Index index = new Index(indexFolder); | |
//Setting the log file name. The log file name can be relative or absolute. | |
index.LogSettings.FileName = @"Log\Log.txt"; | |
//Setting the maximum size of the log file in megabytes. This value must be in the range from 0.1 to 1000. | |
index.LogSettings.MaxSize = 2.0; | |
//Adding documents to index | |
index.AddToIndex(documentFolder); | |
//Searching | |
SearchResults results = index.Search("big"); |
Java
//For complete examples and data files, please go to https://github.com/groupdocs-search/GroupDocs.Search-for-Java | |
String indexFolder = "c:\\MyIndex"; | |
String documentFolder = "c:\\MyDocuments"; | |
//Creating index | |
Index index = new Index(indexFolder); | |
//Setting the log file name. The log file name can be relative or absolute. | |
index.getLogSettings().setFileName("Log\\Log.txt"); | |
//Setting the maximum size of the log file in megabytes. This value must be in the range from 0.1 to 1000. | |
index.getLogSettings().setMaxSize(2.0); | |
//Adding documents to index | |
index.addToIndex(documentFolder); | |
//Searching | |
SearchResults results = index.search("big"); |
Add English Synonyms
This improvement adds English synonyms to default synonym dictionary.
C#
https://github.com/groupdocs-search/GroupDocs.Search-for-.NET | |
//Enabling synonym search in search parameters | |
SearchParameters parameters = new SearchParameters(); | |
parameters.UseSynonymSearch = true; |
Java
//For complete examples and data files, please go to https://github.com/groupdocs-search/GroupDocs.Search-for-Java | |
//Enabling synonym search in search parameters | |
SearchParameters parameters = new SearchParameters(); | |
parameters.setUseSynonymSearch(true); |
Above are the major improvements introduced in version 19.5. Please go through all the other changes in release notes:
Avail these exciting improvements now in your project. This release is available for download. Please share your feedback or concerns here.