コード例 #1
0
        public void TestSpanRegexBug()
        {
            CreateRamDirectories();

            SpanRegexQuery srq = new SpanRegexQuery(new Term("field", "a.*"));
            SpanRegexQuery stq = new SpanRegexQuery(new Term("field", "b.*"));
            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { srq, stq }, 6,
                true);

            // 1. Search the same store which works
            IndexSearcher[] arrSearcher = new IndexSearcher[2];
            arrSearcher[0] = new IndexSearcher(indexStoreA, true);
            arrSearcher[1] = new IndexSearcher(indexStoreB, true);
            MultiSearcher searcher = new MultiSearcher(arrSearcher);
            int numHits = searcher.Search(query, null, 1000).TotalHits;
            arrSearcher[0].Close();
            arrSearcher[1].Close();

            // Will fail here
            // We expect 2 but only one matched
            // The rewriter function only write it once on the first IndexSearcher
            // So it's using term: a1 b1 to search on the second IndexSearcher
            // As a result, it won't match the document in the second IndexSearcher
            Assert.AreEqual(2, numHits);
            indexStoreA.Close();
            indexStoreB.Close();
        }
コード例 #2
0
        public void TestSpanRegex()
        {
            RAMDirectory directory = new RAMDirectory();
            IndexWriter writer = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
            Document doc = new Document();
            // doc.Add(new Field("field", "the quick brown fox jumps over the lazy dog",
            // Field.Store.NO, Field.Index.ANALYZED));
            // writer.AddDocument(doc);
            // doc = new Document();
            doc.Add(new Field("field", "auto update", Field.Store.NO,
                Field.Index.ANALYZED));
            writer.AddDocument(doc);
            doc = new Document();
            doc.Add(new Field("field", "first auto update", Field.Store.NO,
                Field.Index.ANALYZED));
            writer.AddDocument(doc);
            writer.Optimize();
            writer.Close();

            IndexSearcher searcher = new IndexSearcher(directory, true);
            SpanRegexQuery srq = new SpanRegexQuery(new Term("field", "aut.*"));
            SpanFirstQuery sfq = new SpanFirstQuery(srq, 1);
            // SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {srq, stq}, 6,
            // true);
            int numHits = searcher.Search(sfq, null, 1000).TotalHits;
            Assert.AreEqual(1, numHits);
        }
コード例 #3
0
        public void TestSpanRegexBug()
        {
            CreateRamDirectories();

            SpanRegexQuery srq   = new SpanRegexQuery(new Term("field", "a.*"));
            SpanRegexQuery stq   = new SpanRegexQuery(new Term("field", "b.*"));
            SpanNearQuery  query = new SpanNearQuery(new SpanQuery[] { srq, stq }, 6,
                                                     true);

            // 1. Search the same store which works
            IndexSearcher[] arrSearcher = new IndexSearcher[2];
            arrSearcher[0] = new IndexSearcher(indexStoreA, true);
            arrSearcher[1] = new IndexSearcher(indexStoreB, true);
            MultiSearcher searcher = new MultiSearcher(arrSearcher);
            int           numHits  = searcher.Search(query, null, 1000).TotalHits;

            arrSearcher[0].Close();
            arrSearcher[1].Close();

            // Will fail here
            // We expect 2 but only one matched
            // The rewriter function only write it once on the first IndexSearcher
            // So it's using term: a1 b1 to search on the second IndexSearcher
            // As a result, it won't match the document in the second IndexSearcher
            Assert.AreEqual(2, numHits);
            indexStoreA.Close();
            indexStoreB.Close();
        }
コード例 #4
0
        public void TestSpanRegex()
        {
            RAMDirectory directory = new RAMDirectory();
            IndexWriter  writer    = new IndexWriter(directory, new SimpleAnalyzer(), true, IndexWriter.MaxFieldLength.UNLIMITED);
            Document     doc       = new Document();

            // doc.Add(new Field("field", "the quick brown fox jumps over the lazy dog",
            // Field.Store.NO, Field.Index.ANALYZED));
            // writer.AddDocument(doc);
            // doc = new Document();
            doc.Add(new Field("field", "auto update", Field.Store.NO,
                              Field.Index.ANALYZED));
            writer.AddDocument(doc);
            doc = new Document();
            doc.Add(new Field("field", "first auto update", Field.Store.NO,
                              Field.Index.ANALYZED));
            writer.AddDocument(doc);
            writer.Optimize();
            writer.Close();

            IndexSearcher  searcher = new IndexSearcher(directory, true);
            SpanRegexQuery srq      = new SpanRegexQuery(new Term("field", "aut.*"));
            SpanFirstQuery sfq      = new SpanFirstQuery(srq, 1);
            // SpanNearQuery query = new SpanNearQuery(new SpanQuery[] {srq, stq}, 6,
            // true);
            int numHits = searcher.Search(sfq, null, 1000).TotalHits;

            Assert.AreEqual(1, numHits);
        }
コード例 #5
0
ファイル: BaseLuceneStrategy.cs プロジェクト: rotovibe/engage
        public BooleanQuery ParseWholeQueryWc(string searchQuery, string[] fields, QueryParser parser)
        {
            BooleanQuery mq = new BooleanQuery();

            try
            {
                var         qrArr   = searchQuery.Split(null);
                SpanQuery[] compNmQ = new SpanQuery[qrArr.Length];
                SpanQuery[] subsNmQ = new SpanQuery[qrArr.Length];

                for (var i = 0; i < qrArr.Length; i++)
                {
                    compNmQ[i] = new SpanRegexQuery(new Term(fields[0], qrArr[i] + ".*"));
                    subsNmQ[i] = new SpanRegexQuery(new Term(fields[1], qrArr[i] + ".*"));
                }

                SpanQuery compNameQ = new SpanNearQuery(compNmQ, 1, false);
                SpanQuery subsNameQ = new SpanNearQuery(subsNmQ, 1, false);

                mq.Add(compNameQ, Occur.SHOULD);
                mq.Add(subsNameQ, Occur.SHOULD);
            }
            catch (ParseException ex)
            {
                throw new ArgumentException("BaseLuceneStrategy:ParseWholeQueryWc():" + ex.Message);
            }
            return(mq);
        }
コード例 #6
0
ファイル: TestRegexQuery.cs プロジェクト: raol/lucene.net
        private int SpanRegexQueryNrHits(String regex1, String regex2, int slop, bool ordered)
        {
            SpanRegexQuery srq1 = new SpanRegexQuery(NewTerm(regex1));
            SpanRegexQuery srq2 = new SpanRegexQuery(NewTerm(regex2));
            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { srq1, srq2 }, slop, ordered);

            return searcher.Search(query, null, 1000).TotalHits;
        }
コード例 #7
0
        private int SpanRegexQueryNrHits(String regex1, String regex2, int slop, bool ordered)
        {
            SpanRegexQuery srq1  = new SpanRegexQuery(NewTerm(regex1));
            SpanRegexQuery srq2  = new SpanRegexQuery(NewTerm(regex2));
            SpanNearQuery  query = new SpanNearQuery(new SpanQuery[] { srq1, srq2 }, slop, ordered);

            return(searcher.Search(query, null, 1000).TotalHits);
        }
コード例 #8
0
 private static void VisitQuery(SpanRegexQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     AzureQueryLogger.VisitTerm(query.Term, writer);
 }
コード例 #9
0
 private static void VisitQuery(SpanRegexQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     AzureQueryLogger.VisitTerm(query.Term, writer);
 }