Beispiel #1
0
        public virtual void TestNoSuchMultiTermsInSpanFirst()
        {
            //this hasn't been a problem
            FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery  spanNoSuch  = new SpanMultiTermQueryWrapper <MultiTermQuery>(fuzzyNoSuch);
            SpanQuery  spanFirst   = new SpanFirstQuery(spanNoSuch, 10);

            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            WildcardQuery wcNoSuch     = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery     spanWCNoSuch = new SpanMultiTermQueryWrapper <MultiTermQuery>(wcNoSuch);

            spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            RegexpQuery rgxNoSuch     = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery   spanRgxNoSuch = new SpanMultiTermQueryWrapper <MultiTermQuery>(rgxNoSuch);

            spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            PrefixQuery prfxNoSuch     = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery   spanPrfxNoSuch = new SpanMultiTermQueryWrapper <MultiTermQuery>(prfxNoSuch);

            spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);
        }
Beispiel #2
0
        public override object Clone()
        {
            SpanFirstQuery spanFirstQuery = new SpanFirstQuery((SpanQuery)m_match.Clone(), m_end);

            spanFirstQuery.Boost = Boost;
            return(spanFirstQuery);
        }
Beispiel #3
0
        public override System.Object Clone()
        {
            SpanFirstQuery spanFirstQuery = new SpanFirstQuery((SpanQuery)match.Clone(), end);

            spanFirstQuery.SetBoost(GetBoost());
            return(spanFirstQuery);
        }
        public virtual void TestStartPositions()
        {
            Directory dir = NewDirectory();

            // mimic StopAnalyzer
            CharacterRunAutomaton stopSet = new CharacterRunAutomaton((new RegExp("the|a|of")).ToAutomaton());
            Analyzer analyzer = new MockAnalyzer(Random(), MockTokenizer.SIMPLE, true, stopSet);

            RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, analyzer);
            Document doc = new Document();
            doc.Add(NewTextField("field", "the quick brown fox", Field.Store.NO));
            writer.AddDocument(doc);
            Document doc2 = new Document();
            doc2.Add(NewTextField("field", "quick brown fox", Field.Store.NO));
            writer.AddDocument(doc2);

            IndexReader reader = writer.Reader;
            IndexSearcher searcher = NewSearcher(reader);

            // user queries on "starts-with quick"
            SpanQuery sfq = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 1);
            Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);

            // user queries on "starts-with the quick"
            SpanQuery include = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 2);
            sfq = new SpanNotQuery(include, sfq);
            Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);

            writer.Dispose();
            reader.Dispose();
            dir.Dispose();
        }
        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);
        }
Beispiel #6
0
 public virtual void TestPrefix()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match "jumps over extremely very lazy broxn dog"
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
     Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);
 }
Beispiel #7
0
 public virtual void TestWildcard()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "bro?n"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match quick brown fox
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 2);
     Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);
 }
 public virtual void TestWildcard()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "bro?n"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match quick brown fox
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 2);
     Assert.AreEqual(1, Searcher.Search(sfq, 10).TotalHits);
 }
Beispiel #9
0
        public override System.Object Clone()
        {
            var spanFirstQuery = new SpanFirstQuery((SpanQuery)match.Clone(), end)
            {
                Boost = Boost
            };

            return(spanFirstQuery);
        }
Beispiel #10
0
        public virtual void TestSpanFirst()
        {
            SpanTermQuery  term1 = new SpanTermQuery(new Term("field", "five"));
            SpanFirstQuery query = new SpanFirstQuery(term1, 1);

            CheckHits(query, new int[] { 5, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599 });

            Assert.IsTrue(Searcher.Explain(query, 5).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 599).Value > 0.0f);
        }
Beispiel #11
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;
        }
Beispiel #12
0
        public virtual void  TestNpeInSpanNearInSpanFirstInSpanNot()
        {
            int           n       = 5;
            SpanTermQuery hun     = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery term40  = new SpanTermQuery(new Term("field", "forty"));
            SpanTermQuery term40c = (SpanTermQuery)term40.Clone();

            SpanFirstQuery include = new SpanFirstQuery(term40, n);
            SpanNearQuery  near    = new SpanNearQuery(new SpanQuery[] { hun, term40c }, n - 1, true);
            SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
            SpanNotQuery   q       = new SpanNotQuery(include, exclude);

            CheckHits(q, new int[] { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49 });
        }
Beispiel #13
0
        public virtual void TestNpeInSpanNearInSpanFirstInSpanNot()
        {
            int           n       = 5;
            SpanTermQuery hun     = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery term40  = new SpanTermQuery(new Term("field", "forty"));
            SpanTermQuery term40c = (SpanTermQuery)term40.Clone();

            SpanFirstQuery include = new SpanFirstQuery(term40, n);
            SpanNearQuery  near    = new SpanNearQuery(new SpanQuery[] { hun, term40c }, n - 1, true);
            SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
            SpanNotQuery   q       = new SpanNotQuery(include, exclude);

            CheckHits(q, new int[] { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949 });
        }
Beispiel #14
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is SpanFirstQuery))
            {
                return(false);
            }

            SpanFirstQuery other = (SpanFirstQuery)o;

            return(this.m_end == other.m_end && this.m_match.Equals(other.m_match) && this.Boost == other.Boost);
        }
Beispiel #15
0
        public override bool Equals(System.Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is SpanFirstQuery))
            {
                return(false);
            }

            SpanFirstQuery other = (SpanFirstQuery)o;

            return(this.end == other.end && this.match.Equals(other.match) && this.GetBoost() == other.GetBoost());
        }
Beispiel #16
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is SpanFirstQuery))
            {
                return(false);
            }

            SpanFirstQuery other = (SpanFirstQuery)o;

            // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled
            return(this.m_end == other.m_end &&
                   this.m_match.Equals(other.m_match) &&
                   NumericUtils.SingleToSortableInt32(this.Boost) == NumericUtils.SingleToSortableInt32(other.Boost));
        }
Beispiel #17
0
        public virtual void TestSpanFirst()
        {
            SpanQuery match;
            SpanFirstQuery sfq;
            match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            sfq = new SpanFirstQuery(match, 2);
            Spans spans = MultiSpansWrapper.Wrap(IndexReader.Context, sfq);
            CheckSpans(spans, 109, 1, 1, 1);
            //Test more complicated subclause
            SpanQuery[] clauses = new SpanQuery[2];
            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "hundred"));
            match = new SpanNearQuery(clauses, 0, true);
            sfq = new SpanFirstQuery(match, 2);
            CheckSpans(MultiSpansWrapper.Wrap(IndexReader.Context, sfq), 100, 2, 1, 1);

            match = new SpanNearQuery(clauses, 0, false);
            sfq = new SpanFirstQuery(match, 2);
            CheckSpans(MultiSpansWrapper.Wrap(IndexReader.Context, sfq), 100, 2, 1, 1);
        }
Beispiel #18
0
        public override Query Rewrite(IndexReader reader)
        {
            SpanFirstQuery clone = null;

            SpanQuery rewritten = (SpanQuery)match.Rewrite(reader);

            if (rewritten != match)
            {
                clone       = (SpanFirstQuery)this.Clone();
                clone.match = rewritten;
            }

            if (clone != null)
            {
                return(clone);                // some clauses rewrote
            }
            else
            {
                return(this);                // no clauses rewrote
            }
        }
Beispiel #19
0
        public virtual void TestStartPositions()
        {
            Directory dir = NewDirectory();

            // mimic StopAnalyzer
            CharacterRunAutomaton stopSet = new CharacterRunAutomaton((new RegExp("the|a|of")).ToAutomaton());
            Analyzer analyzer             = new MockAnalyzer(Random, MockTokenizer.SIMPLE, true, stopSet);

            RandomIndexWriter writer = new RandomIndexWriter(
#if FEATURE_INSTANCE_TESTDATA_INITIALIZATION
                this,
#endif
                Random, dir, analyzer);
            Document doc = new Document();

            doc.Add(NewTextField("field", "the quick brown fox", Field.Store.NO));
            writer.AddDocument(doc);
            Document doc2 = new Document();

            doc2.Add(NewTextField("field", "quick brown fox", Field.Store.NO));
            writer.AddDocument(doc2);

            IndexReader   reader   = writer.GetReader();
            IndexSearcher searcher = NewSearcher(reader);

            // user queries on "starts-with quick"
            SpanQuery sfq = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 1);

            Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);

            // user queries on "starts-with the quick"
            SpanQuery include = new SpanFirstQuery(new SpanTermQuery(new Term("field", "quick")), 2);

            sfq = new SpanNotQuery(include, sfq);
            Assert.AreEqual(1, searcher.Search(sfq, 10).TotalHits);

            writer.Dispose();
            reader.Dispose();
            dir.Dispose();
        }
Beispiel #20
0
        public virtual void  TestSpanFirst()
        {
            SpanQuery      match;
            SpanFirstQuery sfq;

            match = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            sfq   = new SpanFirstQuery(match, 2);
            Spans spans = sfq.GetSpans(indexReader);

            CheckSpans(spans, 109, 1, 1, 1);
            //Test more complicated subclause
            SpanQuery[] clauses = new SpanQuery[2];
            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "hundred"));
            match      = new SpanNearQuery(clauses, 0, true);
            sfq        = new SpanFirstQuery(match, 2);
            CheckSpans(sfq.GetSpans(indexReader), 100, 2, 1, 1);

            match = new SpanNearQuery(clauses, 0, false);
            sfq   = new SpanFirstQuery(match, 2);
            CheckSpans(sfq.GetSpans(indexReader), 100, 2, 1, 1);
        }
Beispiel #21
0
			private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanFirstQuery enclosingInstance)
			{
				this.reader = reader;
				this.enclosingInstance = enclosingInstance;
				spans = Enclosing_Instance.match.GetSpans(reader);
			}
Beispiel #22
0
 public override object Clone()
 {
     SpanFirstQuery spanFirstQuery = new SpanFirstQuery((SpanQuery)match.Clone(), end);
     spanFirstQuery.Boost = Boost;
     return spanFirstQuery;
 }
Beispiel #23
0
		public override System.Object Clone()
		{
			SpanFirstQuery spanFirstQuery = new SpanFirstQuery((SpanQuery) match.Clone(), end);
			spanFirstQuery.SetBoost(GetBoost());
			return spanFirstQuery;
		}
Beispiel #24
0
			public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanFirstQuery enclosingInstance)
			{
				InitBlock(reader, enclosingInstance);
			}
 public virtual void TestPrefix()
 {
     WildcardQuery wq = new WildcardQuery(new Term("field", "extrem*"));
     SpanQuery swq = new SpanMultiTermQueryWrapper<MultiTermQuery>(wq);
     // will only match "jumps over extremely very lazy broxn dog"
     SpanFirstQuery sfq = new SpanFirstQuery(swq, 3);
     Assert.AreEqual(1, Searcher.Search(sfq, 10).TotalHits);
 }
        public virtual void TestNoSuchMultiTermsInSpanFirst()
        {
            //this hasn't been a problem
            FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery spanNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(fuzzyNoSuch);
            SpanQuery spanFirst = new SpanFirstQuery(spanNoSuch, 10);

            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(wcNoSuch);
            spanFirst = new SpanFirstQuery(spanWCNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(rgxNoSuch);
            spanFirst = new SpanFirstQuery(spanRgxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);

            PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(prfxNoSuch);
            spanFirst = new SpanFirstQuery(spanPrfxNoSuch, 10);
            Assert.AreEqual(0, Searcher.Search(spanFirst, 10).TotalHits);
        }
Beispiel #27
0
		public virtual void  TestNpeInSpanNearInSpanFirstInSpanNot()
		{
			int n = 5;
			SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
			SpanTermQuery term40 = new SpanTermQuery(new Term("field", "forty"));
			SpanTermQuery term40c = (SpanTermQuery) term40.Clone();
			
			SpanFirstQuery include = new SpanFirstQuery(term40, n);
			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{hun, term40c}, n - 1, true);
			SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
			SpanNotQuery q = new SpanNotQuery(include, exclude);
			
			CheckHits(q, new int[]{40, 41, 42, 43, 44, 45, 46, 47, 48, 49});
		}
Beispiel #28
0
 public virtual Query VisitSpanFirstQuery(SpanFirstQuery spanFirstq) { throw new NotImplementedException(); }
 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;
 }
Beispiel #30
0
        public virtual void TestNpeInSpanNearInSpanFirstInSpanNot()
        {
            int n = 5;
            SpanTermQuery hun = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery term40 = new SpanTermQuery(new Term("field", "forty"));
            SpanTermQuery term40c = (SpanTermQuery)term40.Clone();

            SpanFirstQuery include = new SpanFirstQuery(term40, n);
            SpanNearQuery near = new SpanNearQuery(new SpanQuery[] { hun, term40c }, n - 1, true);
            SpanFirstQuery exclude = new SpanFirstQuery(near, n - 1);
            SpanNotQuery q = new SpanNotQuery(include, exclude);

            CheckHits(q, new int[] { 40, 41, 42, 43, 44, 45, 46, 47, 48, 49, 1040, 1041, 1042, 1043, 1044, 1045, 1046, 1047, 1048, 1049, 1140, 1141, 1142, 1143, 1144, 1145, 1146, 1147, 1148, 1149, 1240, 1241, 1242, 1243, 1244, 1245, 1246, 1247, 1248, 1249, 1340, 1341, 1342, 1343, 1344, 1345, 1346, 1347, 1348, 1349, 1440, 1441, 1442, 1443, 1444, 1445, 1446, 1447, 1448, 1449, 1540, 1541, 1542, 1543, 1544, 1545, 1546, 1547, 1548, 1549, 1640, 1641, 1642, 1643, 1644, 1645, 1646, 1647, 1648, 1649, 1740, 1741, 1742, 1743, 1744, 1745, 1746, 1747, 1748, 1749, 1840, 1841, 1842, 1843, 1844, 1845, 1846, 1847, 1848, 1849, 1940, 1941, 1942, 1943, 1944, 1945, 1946, 1947, 1948, 1949 });
        }
Beispiel #31
0
 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanFirstQuery enclosingInstance)
 {
     InitBlock(reader, enclosingInstance);
 }
Beispiel #32
0
		public virtual void  TestSpanFirst()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "five"));
			SpanFirstQuery query = new SpanFirstQuery(term1, 1);
			
			CheckHits(query, new int[]{5, 500, 501, 502, 503, 504, 505, 506, 507, 508, 509, 510, 511, 512, 513, 514, 515, 516, 517, 518, 519, 520, 521, 522, 523, 524, 525, 526, 527, 528, 529, 530, 531, 532, 533, 534, 535, 536, 537, 538, 539, 540, 541, 542, 543, 544, 545, 546, 547, 548, 549, 550, 551, 552, 553, 554, 555, 556, 557, 558, 559, 560, 561, 562, 563, 564, 565, 566, 567, 568, 569, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 580, 581, 582, 583, 584, 585, 586, 587, 588, 589, 590, 591, 592, 593, 594, 595, 596, 597, 598, 599});
			
			Assert.IsTrue(searcher.Explain(query, 5).GetValue() > 0.0f);
			Assert.IsTrue(searcher.Explain(query, 599).GetValue() > 0.0f);
		}
Beispiel #33
0
 private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanFirstQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
     spans = Enclosing_Instance.match.GetSpans(reader);
 }