Esempio n. 1
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);
        }
Esempio n. 2
0
 private static void VisitQuery(SpanFirstQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     writer.WriteLine("End: {0}", (object)query.End);
     writer.WriteLine("Match:");
     ++writer.Indent;
     AzureQueryLogger.VisitQuery(query.Match, writer);
     --writer.Indent;
 }
Esempio n. 3
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            int        end   = DOMUtils.GetAttribute(e, "end", 1);
            XmlElement child = DOMUtils.GetFirstChildElement(e);
            SpanQuery  q     = factory.GetSpanQuery(child);

            SpanFirstQuery sfq = new SpanFirstQuery(q, end);

            sfq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return(sfq);
        }
        public void TestSpanPositionCheck()
        {
            Directory dir = NewDirectory();
            // use simpleanalyzer for more natural tokenization (else "test." is a token)
            Analyzer          analyzer = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true);
            IndexWriterConfig iwc      = NewIndexWriterConfig(TEST_VERSION_CURRENT, analyzer);

            iwc.SetMergePolicy(NewLogMergePolicy());
            RandomIndexWriter iw = new RandomIndexWriter(Random(), dir, iwc);

            FieldType offsetsType = new FieldType(TextField.TYPE_STORED);

            offsetsType.IndexOptions = (IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
            Field    body = new Field("body", "", offsetsType);
            Document doc  = new Document();

            doc.Add(body);

            body.SetStringValue("This is a test.");
            iw.AddDocument(doc);
            body.SetStringValue("Test a one sentence document.");
            iw.AddDocument(doc);

            IndexReader ir = iw.Reader;

            iw.Dispose();

            IndexSearcher       searcher    = NewSearcher(ir);
            PostingsHighlighter highlighter = new PostingsHighlighterAnalyzerHelper(analyzer);
            //PostingsHighlighter highlighter = new PostingsHighlighter() {
            //      @Override
            //      protected Analyzer getIndexAnalyzer(String field)
            //{
            //    return analyzer;
            //}
            //    };
            SpanQuery childQuery = new SpanMultiTermQueryWrapper <WildcardQuery>(new WildcardQuery(new Term("body", "te*")));
            Query     query      = new SpanFirstQuery(childQuery, 1000000);
            TopDocs   topDocs    = searcher.Search(query, null, 10, Sort.INDEXORDER);

            assertEquals(2, topDocs.TotalHits);
            String[] snippets = highlighter.Highlight("body", query, searcher, topDocs);
            assertEquals(2, snippets.Length);
            assertEquals("This is a <b>test</b>.", snippets[0]);
            assertEquals("<b>Test</b> a one sentence document.", snippets[1]);

            ir.Dispose();
            dir.Dispose();
        }
Esempio n. 5
0
 public virtual Query VisitSpanFirstQuery(SpanFirstQuery spanFirstq)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
 public virtual Query VisitSpanFirstQuery(SpanFirstQuery spanFirstq)
 {
     throw new SnNotSupportedException();
 }