Exemple #1
0
        public void TestSingleCharTokenAnalyzer()
        {
            Analyzer analyzer = new SingleCharTokenAnalyzer();
            IndexSearcher src = CreateIndex("[email protected] 1234567890 abcdefgh", analyzer);

            var p = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "field", analyzer)
                        {
                            DefaultOperator = QueryParser.Operator.AND,
                            EnablePositionIncrements = 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);
        }
Exemple #2
0
        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);
        }