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);
        }
        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();
        }
        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;
        }
        public override bool Equals(System.Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            SpanRegexQuery that = (SpanRegexQuery)o;

            return(term.Equals(that.term) && GetBoost() == that.GetBoost());
        }