Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Panel
Description

This feature allows to perform search of words containing wildcards.
There are two possible forms of wildcard to use in wildcard search:

  • ? - quotation mark representing one arbitrary character;
  • ?(N~M) -range of arbitrary characters in an amount from N to M, where N and M must be in the range from 0 to 255.

As well implemented the ability to perform wildcard search using the more flexible object form of search query.

Public API changes

Class WordPattern has been added to GroupDocs.Search namespace.
Constructor WordPattern() nas been added to GroupDocs.Search.WordPattern class.
Method AppendString(string) nas been added to GroupDocs.Search.WordPattern class.
Method AppendCharacter(char) nas been added to GroupDocs.Search.WordPattern class.
Method AppendOneCharacterWildcard() nas been added to GroupDocs.Search.WordPattern class.
Method AppendZeroOrOneCharacterWildcard() nas been added to GroupDocs.Search.WordPattern class.
Method AppendZeroOrMoreCharactersWildcard() nas been added to GroupDocs.Search.WordPattern class.
Method AppendOneOrMoreCharactersWildcard() nas been added to GroupDocs.Search.WordPattern class.
Method AppendWildcard(int, int) nas been added to GroupDocs.Search.WordPattern class.

Method SearchQuery CreateWordPatternQuery(WordPattern) nas been added to GroupDocs.Search.SearchQuery class.

Method SearchQuery GetChild(int) nas been added to GroupDocs.Search.SearchQuery class.

Usecases

The first example shows how to perform wildcard search using the query in text form:

Code Block
titleC#
languagecsharp
string indexFolder = @"c:\MyIndex";
string documentFolder = @"c:\MyDocuments";
  
// Creating index
Index index = new Index(indexFolder);
  
// Adding documents to index
index.AddToIndex(documentFolder);
  
// Searching for words 'affect' or 'effect' in a one document with 'principal', 'principle', 'principles', or 'principally'
SearchResults results1 = index.Search("?ffect & princip?(2~4)");
  
// Searching with a single query for phrases 'assure equal opportunities', 'ensure equal opportunities', and 'sure equal opportunities'
SearchResults results2 = index.Search("\"?(0~2)sure equal opportunities\"");

The next example shows how to perform wildcard search using query in object form:

Code Block
titleC#
languagecsharp
string documentFolder = @"c:\MyDocuments";
  
// Creating index
Index index = new Index(indexFolder);
  
// Adding documents to index
index.AddToIndex(documentFolder);
  
// Constructing query 1
// Word 1 in the query is a pattern '?ffect' for wildcard search
WordPattern pattert11 = new WordPattern();
pattert11.AppendOneCharacterWildcard();
pattert11.AppendString("ffect");
SearchQuery subquery11 = SearchQuery.CreateWordPatternQuery(pattert11);
  
// Word 2 in the query is a pattern 'princip?(2~4)' for wildcard search
WordPattern pattert12 = new WordPattern();
pattert12.AppendString("princip");
pattert12.AppendWildcard(2, 4);
SearchQuery subquery12 = SearchQuery.CreateWordPatternQuery(pattert12);
  
// Creating boolean search query
SearchQuery query1 = SearchQuery.CreateAndQuery(subquery11, subquery12);
  
// Searching with query 1
SearchResults results1 = index.Search(query1, new SearchParameters());
  
// Constructing query 2
// Word 1 in the phrase is a pattern '?(0~2)sure' for wildcard search
WordPattern pattert21 = new WordPattern();
pattert21.AppendWildcard(0, 2);
pattert21.AppendString("sure");
SearchQuery subquery21 = SearchQuery.CreateWordPatternQuery(pattert21);
  
// Word 2 in the phrase is searched with different word forms ('equal', 'equals', 'equally', etc.)
SearchQuery subquery22 = SearchQuery.CreateWordQuery("equal");
subquery22.SearchParameters = new SearchParameters() { UseWordFormsSearch = true };
  
// Word 3 in the phrase is searched with maximum 2 differences of fuzzy search
SearchQuery subquery23 = SearchQuery.CreateWordQuery("opportunities");
subquery23.SearchParameters = new SearchParameters();
subquery23.SearchParameters.FuzzySearch.Enabled = true;
subquery23.SearchParameters.FuzzySearch.FuzzyAlgorithm = new TableDiscreteFunction(2);
  
// Creating phrase search query
SearchQuery query2 = SearchQuery.CreatePhraseSearchQuery(subquery21, subquery22, subquery23);
  
// Searching with query 2
SearchResults results2 = index.Search(query2, new SearchParameters());