private QueryProvider <TLuceneEntity> TokenizedWildCard <TResult>(string term, Expression <Func <TLuceneEntity, TResult> > selector, Occur occur) { if (term.Contains(" ")) { this.Open(occur); var termsList = term.Split(' '); termsList = RemoveEmpty(termsList); var wildCards = new List <PermutermWildcardQuery>(); for (int i = 0; i < termsList.Length; i++) { if (i == 0) { wildCards.Add(new PermutermWildcardQuery(new Term(selector.GetName(), $"*{termsList[i]}"))); } else if (i == termsList.Length - 1) { wildCards.Add(new PermutermWildcardQuery(new Term(selector.GetName(), $"{termsList[i]}*"))); } else { wildCards.Add(new PermutermWildcardQuery(new Term(selector.GetName(), $"{termsList[i]}"))); } } foreach (var item in wildCards) { _current.Add(item, Occur.SHOULD); } this.Close(); } else { var query = new PermutermWildcardQuery(new Term(selector.GetName(), $"*{term}*")); _current.Add(query, occur); } _containsWildCard = true; return(this); }
private QueryProvider <TLuceneEntity> TokenizedIncludePhrase <TResult>(string term, Expression <Func <TLuceneEntity, TResult> > selector, Occur occur) { if (term.Contains(" ")) { this.Open(occur); var termsList = term.Split(' '); termsList = RemoveEmpty(termsList); var wildCards = new List <PermutermWildcardQuery>(); for (int i = 0; i < termsList.Length; i++) { wildCards.Add(new PermutermWildcardQuery(new Term(selector.GetName(), $"{termsList[i]}"))); } var multiPhrase = new MultiPhraseQuery(); foreach (var item in termsList) { multiPhrase.Add(new Term(selector.GetName(), item)); } multiPhrase.Slop = 8; _current.Add(multiPhrase, Occur.MUST); this.Close(); } else { var query = new PermutermWildcardQuery(new Term(selector.GetName(), $"{term}")); _current.Add(query, occur); } _containsWildCard = true; return(this); }