public void TestShingleAnalyzerWrapperBooleanQuery() { Analyzer analyzer = new ShingleAnalyzerWrapper(new WhitespaceAnalyzer(), 2); Searcher = SetUpSearcher(analyzer); var q = new BooleanQuery(); var ts = analyzer.TokenStream("content", new StringReader("test sentence")); var termAtt = ts.AddAttribute<ITermAttribute>(); while (ts.IncrementToken()) { var termText = termAtt.Term; q.Add(new TermQuery(new Term("content", termText)), Occur.SHOULD); } var hits = Searcher.Search(q, null, 1000).ScoreDocs; var ranks = new[] {1, 2, 0}; CompareRanks(hits, ranks); }
public void TestShingleAnalyzerWrapperPhraseQuery() { Analyzer analyzer = new ShingleAnalyzerWrapper(new WhitespaceAnalyzer(), 2); Searcher = SetUpSearcher(analyzer); var q = new PhraseQuery(); var ts = analyzer.TokenStream("content", new StringReader("this sentence")); var j = -1; var posIncrAtt = ts.AddAttribute<IPositionIncrementAttribute>(); var termAtt = ts.AddAttribute<ITermAttribute>(); while (ts.IncrementToken()) { j += posIncrAtt.PositionIncrement; var termText = termAtt.Term; q.Add(new Term("content", termText), j); } var hits = Searcher.Search(q, null, 1000).ScoreDocs; var ranks = new[] {0}; CompareRanks(hits, ranks); }