public void TestSingleCharTokenAnalyzer() { Analyzer analyzer = new SingleCharTokenAnalyzer(); IndexSearcher src = CreateIndex("[email protected] 1234567890 abcdefgh", analyzer); QueryParser p = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "field", analyzer); p.SetDefaultOperator(QueryParser.Operator.AND); p.SetEnablePositionIncrements(true); TopDocs td = null; td = src.Search(p.Parse("usergmail"), 10); Assert.AreEqual(0, td.totalHits); td = src.Search(p.Parse("gmailcom"), 10); Assert.AreEqual(0, td.totalHits); td = src.Search(p.Parse("678"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("someuser"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("omeuse"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("omeuse 6789"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("user gmail"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("\"user gmail\""), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("user@gmail"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("gmail.com"), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("\"gmail.com 1234\""), 10); Assert.AreEqual(1, td.totalHits); td = src.Search(p.Parse("\"gmail.com defg\""), 10); Assert.AreEqual(0, td.totalHits); td = src.Search(p.Parse("gmail.com defg"), 10); Assert.AreEqual(1, td.totalHits); }
public virtual void TestPositionIncrement() { bool dflt = StopFilter.GetEnablePositionIncrementsDefault(); StopFilter.SetEnablePositionIncrementsDefault(true); try { QueryParser qp = new QueryParser("a", new StopAnalyzer(new System.String[]{"the", "in", "are", "this"})); qp.SetEnablePositionIncrements(true); System.String qtxt = "\"the words in poisitions pos02578 are stopped in this phrasequery\""; // 0 2 5 7 8 int[] expectedPositions = new int[]{1, 3, 4, 6, 9}; PhraseQuery pq = (PhraseQuery) qp.Parse(qtxt); //System.out.println("Query text: "+qtxt); //System.out.println("Result: "+pq); Term[] t = pq.GetTerms(); int[] pos = pq.GetPositions(); for (int i = 0; i < t.Length; i++) { //System.out.println(i+". "+t[i]+" pos: "+pos[i]); Assert.AreEqual(expectedPositions[i], pos[i], "term " + i + " = " + t[i] + " has wrong term-position!"); } } finally { StopFilter.SetEnablePositionIncrementsDefault(dflt); } }