Matches spans containing a term.
상속: Lucene.Net.Search.Spans.SpanQuery
예제 #1
0
		public virtual void  TestSingleSpanQuery()
		{
			
			Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
			System.String[] expectedIds = new System.String[]{"B", "D", "1", "2", "3", "4", "A"};
			float[] expectedScores = new float[]{0.625f, 0.45927936f, 0.35355338f, 0.35355338f, 0.35355338f, 0.35355338f, 0.26516503f};
			assertHits(searcher2, spanQuery, "single span query", expectedIds, expectedScores);
		}
예제 #2
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string value = DOMUtils.GetNonBlankTextOrFail(e);
            SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, value));

            stq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
            return stq;
        }
		public virtual void  TestSpanTermQuery()
		{
			SpanTermQuery stq;
			Spans spans;
			stq = new SpanTermQuery(new Term(PayloadHelper.FIELD, "seventy"));
			spans = stq.GetSpans(indexReader);
			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
			CheckSpans(spans, 100, 1, 1, 1);
			
			stq = new SpanTermQuery(new Term(PayloadHelper.NO_PAYLOAD_FIELD, "seventy"));
			spans = stq.GetSpans(indexReader);
			Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
			CheckSpans(spans, 100, 0, 0, 0);
		}
예제 #4
0
        public virtual void TestSpanPositionRange()
        {
            SpanPositionRangeQuery query;
            SpanTermQuery          term1 = new SpanTermQuery(new Term("field", "five"));

            query = new SpanPositionRangeQuery(term1, 1, 2);
            CheckHits(query, new int[] { 25, 35, 45, 55, 65, 75, 85, 95 });
            Assert.IsTrue(Searcher.Explain(query, 25).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 95).Value > 0.0f);

            query = new SpanPositionRangeQuery(term1, 0, 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 });

            query = new SpanPositionRangeQuery(term1, 6, 7);
            CheckHits(query, new int[] { });
        }
예제 #5
0
        public virtual void TestSpanOr()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "thirty"));
            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "three"));
            SpanNearQuery near1 = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 0, true);
            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
            SpanTermQuery term4 = new SpanTermQuery(new Term("field", "seven"));
            SpanNearQuery near2 = new SpanNearQuery(new SpanQuery[] { term3, term4 }, 0, true);

            SpanOrQuery query = new SpanOrQuery(near1, near2);

            CheckHits(query, new int[] { 33, 47, 133, 147, 233, 247, 333, 347, 433, 447, 533, 547, 633, 647, 733, 747, 833, 847, 933, 947, 1033, 1047, 1133, 1147, 1233, 1247, 1333, 1347, 1433, 1447, 1533, 1547, 1633, 1647, 1733, 1747, 1833, 1847, 1933, 1947 });

            Assert.IsTrue(Searcher.Explain(query, 33).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 947).Value > 0.0f);
        }
예제 #6
0
        public virtual void TestNpeInSpanNearWithSpanNot()
        {
            SpanTermQuery term1   = new SpanTermQuery(new Term("field", "eight"));
            SpanTermQuery term2   = new SpanTermQuery(new Term("field", "one"));
            SpanNearQuery near    = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 4, true);
            SpanTermQuery hun     = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery term3   = new SpanTermQuery(new Term("field", "forty"));
            SpanNearQuery exclude = new SpanNearQuery(new SpanQuery[] { hun, term3 }, 1, true);

            SpanNotQuery query = new SpanNotQuery(near, exclude);

            CheckHits(query, new int[] { 801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891 });

            Assert.IsTrue(Searcher.Explain(query, 801).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 891).Value > 0.0f);
        }
예제 #7
0
        public virtual void TestSpanWithMultipleNotSingle()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
            SpanNearQuery near  = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 4, true);
            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));

            SpanOrQuery or = new SpanOrQuery(term3);

            SpanNotQuery query = new SpanNotQuery(near, or);

            CheckHits(query, new int[] { 801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891 });

            Assert.IsTrue(searcher.Explain(query, 801).Value > 0.0f);
            Assert.IsTrue(searcher.Explain(query, 891).Value > 0.0f);
        }
예제 #8
0
        public virtual void TestSpanNotWindowNeg()
        {
            //test handling of invalid window < 0
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
            SpanNearQuery near  = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 4, true);
            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));

            SpanOrQuery or = new SpanOrQuery(term3);

            SpanNotQuery query = new SpanNotQuery(near, or);

            CheckHits(query, new int[] { 801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891 });

            Assert.IsTrue(Searcher.Explain(query, 801).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 891).Value > 0.0f);
        }
예제 #9
0
        public virtual void TestSpanPayloadCheck()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five"));
            BytesRef      pay   = new BytesRef(("pos: " + 5).GetBytes(IOUtils.CHARSET_UTF_8));
            SpanQuery     query = new SpanPayloadCheckQuery(term1, new List <byte[]>()
            {
                pay.Bytes
            });

            CheckHits(query, new int[] { 1125, 1135, 1145, 1155, 1165, 1175, 1185, 1195, 1225, 1235, 1245, 1255, 1265, 1275, 1285, 1295, 1325, 1335, 1345, 1355, 1365, 1375, 1385, 1395, 1425, 1435, 1445, 1455, 1465, 1475, 1485, 1495, 1525, 1535, 1545, 1555, 1565, 1575, 1585, 1595, 1625, 1635, 1645, 1655, 1665, 1675, 1685, 1695, 1725, 1735, 1745, 1755, 1765, 1775, 1785, 1795, 1825, 1835, 1845, 1855, 1865, 1875, 1885, 1895, 1925, 1935, 1945, 1955, 1965, 1975, 1985, 1995 });
            Assert.IsTrue(Searcher.Explain(query, 1125).Value > 0.0f);

            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "hundred"));
            SpanNearQuery snq;

            SpanQuery[]    clauses;
            IList <byte[]> list;
            BytesRef       pay2;

            clauses    = new SpanQuery[2];
            clauses[0] = term1;
            clauses[1] = term2;
            snq        = new SpanNearQuery(clauses, 0, true);
            pay        = new BytesRef(("pos: " + 0).GetBytes(IOUtils.CHARSET_UTF_8));
            pay2       = new BytesRef(("pos: " + 1).GetBytes(IOUtils.CHARSET_UTF_8));
            list       = new List <byte[]>();
            list.Add(pay.Bytes);
            list.Add(pay2.Bytes);
            query = new SpanNearPayloadCheckQuery(snq, list);
            CheckHits(query, new int[] { 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 });
            clauses    = new SpanQuery[3];
            clauses[0] = term1;
            clauses[1] = term2;
            clauses[2] = new SpanTermQuery(new Term("field", "five"));
            snq        = new SpanNearQuery(clauses, 0, true);
            pay        = new BytesRef(("pos: " + 0).GetBytes(IOUtils.CHARSET_UTF_8));
            pay2       = new BytesRef(("pos: " + 1).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay3 = new BytesRef(("pos: " + 2).GetBytes(IOUtils.CHARSET_UTF_8));

            list = new List <byte[]>();
            list.Add(pay.Bytes);
            list.Add(pay2.Bytes);
            list.Add(pay3.Bytes);
            query = new SpanNearPayloadCheckQuery(snq, list);
            CheckHits(query, new int[] { 505 });
        }
예제 #10
0
        public virtual void TestShrinkToAfterShortestMatch3()
        {
            RAMDirectory directory = new RAMDirectory();
            IndexWriter  writer    = new IndexWriter(directory, new TestPayloadAnalyzer(this), IndexWriter.MaxFieldLength.LIMITED);
            Document     doc       = new Document();

            doc.Add(new Field("content", new System.IO.StreamReader(new System.IO.MemoryStream(System.Text.Encoding.ASCII.GetBytes("j k a l f k k p a t a k l k t a")))));
            writer.AddDocument(doc);
            writer.Close();

            IndexSearcher is_Renamed = new IndexSearcher(directory, true);

            SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
            SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));

            SpanQuery[]   sqs   = new SpanQuery[] { stq1, stq2 };
            SpanNearQuery snq   = new SpanNearQuery(sqs, 0, true);
            Spans         spans = snq.GetSpans(is_Renamed.IndexReader);

            TopDocs topDocs = is_Renamed.Search(snq, 1);

            System.Collections.Hashtable payloadSet = new System.Collections.Hashtable();
            for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
            {
                while (spans.Next())
                {
                    System.Collections.Generic.ICollection <byte[]> payloads = spans.GetPayload();

                    for (System.Collections.IEnumerator it = payloads.GetEnumerator(); it.MoveNext();)
                    {
                        CollectionsHelper.AddIfNotContains(payloadSet, new System.String(System.Text.UTF8Encoding.UTF8.GetChars((byte[])it.Current)));
                    }
                }
            }
            Assert.AreEqual(2, payloadSet.Count);
            if (DEBUG)
            {
                System.Collections.IEnumerator pit = payloadSet.GetEnumerator();
                while (pit.MoveNext())
                {
                    System.Console.Out.WriteLine("match:" + pit.Current);
                }
            }
            Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
            Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
        }
예제 #11
0
        public virtual void  TestSpanWithMultipleNotMany()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
            SpanNearQuery near  = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 4, true);
            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));
            SpanTermQuery term4 = new SpanTermQuery(new Term("field", "sixty"));
            SpanTermQuery term5 = new SpanTermQuery(new Term("field", "eighty"));

            SpanOrQuery or = new SpanOrQuery(new SpanQuery[] { term3, term4, term5 });

            SpanNotQuery query = new SpanNotQuery(near, or);

            CheckHits(query, new int[] { 801, 821, 831, 851, 871, 891 });

            Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
            Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
        }
예제 #12
0
        public virtual void  TestSpansSkipTo()
        {
            SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy"));
            SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy"));
            Spans         s1 = t1.GetSpans(searcher.IndexReader, null);
            Spans         s2 = t2.GetSpans(searcher.IndexReader, null);

            Assert.IsTrue(s1.Next(null));
            Assert.IsTrue(s2.Next(null));

            bool hasMore = true;

            do
            {
                hasMore = SkipToAccoringToJavaDocs(s1, s1.Doc());
                Assert.AreEqual(hasMore, s2.SkipTo(s2.Doc(), null));
                Assert.AreEqual(s1.Doc(), s2.Doc());
            }while (hasMore);
        }
예제 #13
0
        public virtual void TestShrinkToAfterShortestMatch()
        {
            Directory         directory = NewDirectory();
            RandomIndexWriter writer    = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new TestPayloadAnalyzer(this)));

            Document doc = new Document();

            doc.Add(new TextField("content", new StringReader("a b c d e f g h i j a k")));
            writer.AddDocument(doc);

            IndexReader   reader = writer.Reader;
            IndexSearcher @is    = NewSearcher(reader);

            writer.Dispose();

            SpanTermQuery stq1 = new SpanTermQuery(new Term("content", "a"));
            SpanTermQuery stq2 = new SpanTermQuery(new Term("content", "k"));

            SpanQuery[]   sqs   = new SpanQuery[] { stq1, stq2 };
            SpanNearQuery snq   = new SpanNearQuery(sqs, 1, true);
            Spans         spans = MultiSpansWrapper.Wrap(@is.TopReaderContext, snq);

            TopDocs          topDocs    = @is.Search(snq, 1);
            HashSet <string> payloadSet = new HashSet <string>();

            for (int i = 0; i < topDocs.ScoreDocs.Length; i++)
            {
                while (spans.Next())
                {
                    ICollection <sbyte[]> payloads = spans.Payload;

                    foreach (sbyte[] payload in payloads)
                    {
                        payloadSet.Add(Encoding.UTF8.GetString((byte[])(Array)payload));
                    }
                }
            }
            Assert.AreEqual(2, payloadSet.Count);
            Assert.IsTrue(payloadSet.Contains("a:Noise:10"));
            Assert.IsTrue(payloadSet.Contains("k:Noise:11"));
            reader.Dispose();
            directory.Dispose();
        }
예제 #14
0
        public virtual void TestSpansSkipTo()
        {
            SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy"));
            SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy"));
            Spans         s1 = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, t1);
            Spans         s2 = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, t2);

            Assert.IsTrue(s1.Next());
            Assert.IsTrue(s2.Next());

            bool hasMore = true;

            do
            {
                hasMore = SkipToAccoringToJavaDocs(s1, s1.Doc() + 1);
                Assert.AreEqual(hasMore, s2.SkipTo(s2.Doc() + 1));
                Assert.AreEqual(s1.Doc(), s2.Doc());
            } while (hasMore);
        }
예제 #15
0
        public virtual void  TestSpans1()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("first", "sally"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery qA = new SpanOrQuery(new SpanQuery[] { q1, q2 });
            SpanQuery qB = new FieldMaskingSpanQuery(qA, "id");

            Check(qA, new int[] { 0, 1, 2, 4 });
            Check(qB, new int[] { 0, 1, 2, 4 });

            Spans spanA = qA.GetSpans(searcher.GetIndexReader());
            Spans spanB = qB.GetSpans(searcher.GetIndexReader());

            while (spanA.Next())
            {
                Assert.IsTrue(spanB.Next(), "spanB not still going");
                Assert.AreEqual(S(spanA), S(spanB), "spanA not equal spanB");
            }
            Assert.IsTrue(!(spanB.Next()), "spanB still going even tough spanA is done");
        }
예제 #16
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);
        }
        public virtual void TestSpans1()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("first", "sally"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery qA = new SpanOrQuery(q1, q2);
            SpanQuery qB = new FieldMaskingSpanQuery(qA, "id");

            Check(qA, new int[] { 0, 1, 2, 4 });
            Check(qB, new int[] { 0, 1, 2, 4 });

            Spans spanA = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, qA);
            Spans spanB = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, qB);

            while (spanA.Next())
            {
                Assert.IsTrue(spanB.Next(), "spanB not still going");
                Assert.AreEqual(s(spanA), s(spanB), "spanA not equal spanB");
            }
            Assert.IsTrue(!(spanB.Next()), "spanB still going even tough spanA is done");
        }
예제 #18
0
        public virtual void TestSpanComplex1()
        {
            SpanTermQuery t1  = new SpanTermQuery(new Term("field", "six"));
            SpanTermQuery t2  = new SpanTermQuery(new Term("field", "hundred"));
            SpanNearQuery tt1 = new SpanNearQuery(new SpanQuery[] { t1, t2 }, 0, true);

            SpanTermQuery t3  = new SpanTermQuery(new Term("field", "seven"));
            SpanTermQuery t4  = new SpanTermQuery(new Term("field", "hundred"));
            SpanNearQuery tt2 = new SpanNearQuery(new SpanQuery[] { t3, t4 }, 0, true);

            SpanTermQuery t5 = new SpanTermQuery(new Term("field", "seven"));
            SpanTermQuery t6 = new SpanTermQuery(new Term("field", "six"));

            SpanOrQuery to1 = new SpanOrQuery(tt1, tt2);
            SpanOrQuery to2 = new SpanOrQuery(t5, t6);

            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { to1, to2 }, 100, true);

            CheckHits(query, new int[] { 606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797, 1606, 1607, 1626, 1627, 1636, 1637, 1646, 1647, 1656, 1657, 1666, 1667, 1676, 1677, 1686, 1687, 1696, 1697, 1706, 1707, 1726, 1727, 1736, 1737, 1746, 1747, 1756, 1757, 1766, 1767, 1776, 1777, 1786, 1787, 1796, 1797 });
        }
예제 #19
0
        public virtual void  TestSpans0()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("gender", "female"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery q  = new SpanOrQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "gender") });

            Check(q, new int[] { 0, 1, 2, 3, 4 });

            Spans span = q.GetSpans(searcher.GetIndexReader());

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(0, 0, 1), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(1, 0, 1), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(1, 1, 2), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(2, 0, 1), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(2, 1, 2), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(2, 2, 3), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(3, 0, 1), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(4, 0, 1), S(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(S(4, 1, 2), S(span));

            Assert.AreEqual(false, span.Next());
        }
예제 #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);
        }
예제 #21
0
        public virtual void TestNoSuchMultiTermsInNear()
        {
            //test to make sure non existent multiterms aren't throwing null pointer exceptions
            FuzzyQuery fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery  spanNoSuch  = new SpanMultiTermQueryWrapper <MultiTermQuery>(fuzzyNoSuch);
            SpanQuery  term        = new SpanTermQuery(new Term("field", "brown"));
            SpanQuery  near        = new SpanNearQuery(new SpanQuery[] { term, spanNoSuch }, 1, true);

            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);
            //flip order
            near = new SpanNearQuery(new SpanQuery[] { spanNoSuch, term }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

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

            near = new SpanNearQuery(new SpanQuery[] { term, spanWCNoSuch }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

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

            near = new SpanNearQuery(new SpanQuery[] { term, spanRgxNoSuch }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

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

            near = new SpanNearQuery(new SpanQuery[] { term, spanPrfxNoSuch }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

            //test single noSuch
            near = new SpanNearQuery(new SpanQuery[] { spanPrfxNoSuch }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);

            //test double noSuch
            near = new SpanNearQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch }, 1, true);
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);
        }
        public virtual void TestSpans0()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("gender", "female"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery q  = new SpanOrQuery(q1, new FieldMaskingSpanQuery(q2, "gender"));

            Check(q, new int[] { 0, 1, 2, 3, 4 });

            Spans span = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, q);

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(0, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(1, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(1, 1, 2), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 1, 2), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 2, 3), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(3, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(4, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(4, 1, 2), s(span));

            Assert.AreEqual(false, span.Next());
        }
예제 #23
0
        public virtual void TestSpanNot()
        {
            SpanQuery[] clauses = new SpanQuery[2];
            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));
            SpanQuery    spq = new SpanNearQuery(clauses, 5, true);
            SpanNotQuery snq = new SpanNotQuery(spq, new SpanTermQuery(new Term(PayloadHelper.FIELD, "two")));

            Directory         directory = NewDirectory();
            RandomIndexWriter writer    = new RandomIndexWriter(Random(), directory, NewIndexWriterConfig(TEST_VERSION_CURRENT, new PayloadAnalyzer(this)).SetSimilarity(Similarity));

            Document doc = new Document();

            doc.Add(NewTextField(PayloadHelper.FIELD, "one two three one four three", Field.Store.YES));
            writer.AddDocument(doc);
            IndexReader reader = writer.Reader;

            writer.Dispose();

            CheckSpans(MultiSpansWrapper.Wrap(reader.Context, snq), 1, new int[] { 2 });
            reader.Dispose();
            directory.Dispose();
        }
예제 #24
0
        public virtual void TestHeavilyNestedSpanQuery()
        {
            Spans         spans;
            IndexSearcher searcher = Searcher;

            SpanQuery[] clauses = new SpanQuery[3];
            clauses[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "one"));
            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "two"));
            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "three"));

            SpanNearQuery spanNearQuery = new SpanNearQuery(clauses, 5, true);

            clauses    = new SpanQuery[3];
            clauses[0] = spanNearQuery;
            clauses[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "five"));
            clauses[2] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "six"));

            SpanNearQuery spanNearQuery2 = new SpanNearQuery(clauses, 6, true);

            SpanQuery[] clauses2 = new SpanQuery[2];
            clauses2[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "eleven"));
            clauses2[1] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "ten"));
            SpanNearQuery spanNearQuery3 = new SpanNearQuery(clauses2, 2, false);

            SpanQuery[] clauses3 = new SpanQuery[3];
            clauses3[0] = new SpanTermQuery(new Term(PayloadHelper.FIELD, "nine"));
            clauses3[1] = spanNearQuery2;
            clauses3[2] = spanNearQuery3;

            SpanNearQuery nestedSpanNearQuery = new SpanNearQuery(clauses3, 6, false);

            spans = MultiSpansWrapper.Wrap(searcher.TopReaderContext, nestedSpanNearQuery);
            Assert.IsTrue(spans != null, "spans is null and it shouldn't be");
            CheckSpans(spans, 2, new int[] { 8, 8 });
            CloseIndexReader.Dispose();
            Directory.Dispose();
        }
예제 #25
0
        public override SpanQuery GetSpanQuery(XmlElement e)
        {
            string fieldName = DOMUtils.GetAttributeWithInheritanceOrFail(e, "fieldName");
            string value = DOMUtils.GetNonBlankTextOrFail(e);

            List<SpanQuery> clausesList = new List<SpanQuery>();

            TokenStream ts = null;
            try
            {
                ts = analyzer.TokenStream(fieldName, value);
                ITermToBytesRefAttribute termAtt = ts.AddAttribute<ITermToBytesRefAttribute>();
                BytesRef bytes = termAtt.BytesRef;
                ts.Reset();
                while (ts.IncrementToken())
                {
                    termAtt.FillBytesRef();
                    SpanTermQuery stq = new SpanTermQuery(new Term(fieldName, BytesRef.DeepCopyOf(bytes)));
                    clausesList.Add(stq);
                }
                ts.End();
                SpanOrQuery soq = new SpanOrQuery(clausesList.ToArray(/*new SpanQuery[clausesList.size()]*/));
                soq.Boost = DOMUtils.GetAttribute(e, "boost", 1.0f);
                return soq;
            }
#pragma warning disable 168
            catch (IOException ioe)
#pragma warning restore 168
            {
                throw new ParserException("IOException parsing value:" + value);
            }
            finally
            {
                IOUtils.CloseWhileHandlingException(ts);
            }
        }
예제 #26
0
        public virtual void TestNoSuchMultiTermsInNotNear()
        {
            //test to make sure non existent multiterms aren't throwing non-matching field exceptions
            FuzzyQuery   fuzzyNoSuch = new FuzzyQuery(new Term("field", "noSuch"), 1, 0, 1, false);
            SpanQuery    spanNoSuch  = new SpanMultiTermQueryWrapper <MultiTermQuery>(fuzzyNoSuch);
            SpanQuery    term        = new SpanTermQuery(new Term("field", "brown"));
            SpanNotQuery notNear     = new SpanNotQuery(term, spanNoSuch, 0, 0);

            Assert.AreEqual(1, Searcher.Search(notNear, 10).TotalHits);

            //flip
            notNear = new SpanNotQuery(spanNoSuch, term, 0, 0);
            Assert.AreEqual(0, Searcher.Search(notNear, 10).TotalHits);

            //both noSuch
            notNear = new SpanNotQuery(spanNoSuch, spanNoSuch, 0, 0);
            Assert.AreEqual(0, Searcher.Search(notNear, 10).TotalHits);

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

            notNear = new SpanNotQuery(term, spanWCNoSuch, 0, 0);
            Assert.AreEqual(1, Searcher.Search(notNear, 10).TotalHits);

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

            notNear = new SpanNotQuery(term, spanRgxNoSuch, 1, 1);
            Assert.AreEqual(1, Searcher.Search(notNear, 10).TotalHits);

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

            notNear = new SpanNotQuery(term, spanPrfxNoSuch, 1, 1);
            Assert.AreEqual(1, Searcher.Search(notNear, 10).TotalHits);
        }
예제 #27
0
		public virtual void  TestSpanNearOrdered()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "nine"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "six"));
			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
			CheckHits(query, new int[]{906, 926, 936, 946, 956, 966, 976, 986, 996});
		}
예제 #28
0
		public virtual void  TestSpanNearUnordered()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "nine"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "six"));
			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, false);
			
			CheckHits(query, new int[]{609, 629, 639, 649, 659, 669, 679, 689, 699, 906, 926, 936, 946, 956, 966, 976, 986, 996});
		}
예제 #29
0
        public virtual void TestSpansSkipTo()
        {
            SpanTermQuery t1 = new SpanTermQuery(new Term("field", "seventy"));
            SpanTermQuery t2 = new SpanTermQuery(new Term("field", "seventy"));
            Spans s1 = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, t1);
            Spans s2 = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, t2);

            Assert.IsTrue(s1.Next());
            Assert.IsTrue(s2.Next());

            bool hasMore = true;

            do
            {
                hasMore = SkipToAccoringToJavaDocs(s1, s1.Doc() + 1);
                Assert.AreEqual(hasMore, s2.SkipTo(s2.Doc() + 1));
                Assert.AreEqual(s1.Doc(), s2.Doc());
            } while (hasMore);
        }
 private static void VisitQuery(SpanTermQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     AzureQueryLogger.VisitTerm(query.Term, writer);
 }
예제 #31
0
		public virtual void  TestSpanOr()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "thirty"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "three"));
			SpanNearQuery near1 = new SpanNearQuery(new SpanQuery[]{term1, term2}, 0, true);
			SpanTermQuery term3 = new SpanTermQuery(new Term("Field", "forty"));
			SpanTermQuery term4 = new SpanTermQuery(new Term("Field", "seven"));
			SpanNearQuery near2 = new SpanNearQuery(new SpanQuery[]{term3, term4}, 0, true);
			
			SpanOrQuery query = new SpanOrQuery(new SpanQuery[]{near1, near2});
			
			CheckHits(query, new int[]{33, 47, 133, 147, 233, 247, 333, 347, 433, 447, 533, 547, 633, 647, 733, 747, 833, 847, 933, 947});
			
			Assert.IsTrue(searcher.Explain(query, 33).GetValue() > 0.0f);
			Assert.IsTrue(searcher.Explain(query, 947).GetValue() > 0.0f);
		}
예제 #32
0
		public virtual void  TestSpanExactNested()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "three"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "hundred"));
			SpanNearQuery near1 = new SpanNearQuery(new SpanQuery[]{term1, term2}, 0, true);
			SpanTermQuery term3 = new SpanTermQuery(new Term("Field", "thirty"));
			SpanTermQuery term4 = new SpanTermQuery(new Term("Field", "three"));
			SpanNearQuery near2 = new SpanNearQuery(new SpanQuery[]{term3, term4}, 0, true);
			
			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{near1, near2}, 0, true);
			
			CheckHits(query, new int[]{333});
			
			Assert.IsTrue(searcher.Explain(query, 333).GetValue() > 0.0f);
		}
예제 #33
0
 public virtual void TestMultipleDifferentSpanQueries()
 {
     Query spanQuery1 = new SpanTermQuery(new Term(FIELD_TEXT, "should"));
     Query spanQuery2 = new SpanTermQuery(new Term(FIELD_TEXT, "we"));
     BooleanQuery query = new BooleanQuery();
     query.Add(spanQuery1, BooleanClause.Occur.MUST);
     query.Add(spanQuery2, BooleanClause.Occur.MUST);
     string[] expectedIds = new string[] { "D", "A" };
     // these values were pre LUCENE-413
     // final float[] expectedScores = new float[] { 0.93163157f, 0.20698164f };
     float[] expectedScores = new float[] { 1.0191123f, 0.93163157f };
     AssertHits(Searcher2, query, "multiple different span queries", expectedIds, expectedScores);
 }
        public virtual void TestRewrite2()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("last", "smith"));
            SpanQuery q2 = new SpanTermQuery(new Term("last", "jones"));
            SpanQuery q = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "last") }, 1, true);
            Query qr = Searcher.Rewrite(q);

            QueryUtils.CheckEqual(q, qr);

            HashSet<Term> set = new HashSet<Term>();
            qr.ExtractTerms(set);
            Assert.AreEqual(2, set.Count);
        }
 public virtual void TestSimple1()
 {
     SpanQuery q1 = new SpanTermQuery(new Term("first", "james"));
     SpanQuery q2 = new SpanTermQuery(new Term("last", "jones"));
     SpanQuery q = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "first") }, -1, false);
     Check(q, new int[] { 0, 2 });
     q = new SpanNearQuery(new SpanQuery[] { new FieldMaskingSpanQuery(q2, "first"), q1 }, -1, false);
     Check(q, new int[] { 0, 2 });
     q = new SpanNearQuery(new SpanQuery[] { q2, new FieldMaskingSpanQuery(q1, "last") }, -1, false);
     Check(q, new int[] { 0, 2 });
     q = new SpanNearQuery(new SpanQuery[] { new FieldMaskingSpanQuery(q1, "last"), q2 }, -1, false);
     Check(q, new int[] { 0, 2 });
 }
 public virtual void TestNoop1()
 {
     SpanQuery q1 = new SpanTermQuery(new Term("last", "smith"));
     SpanQuery q2 = new SpanTermQuery(new Term("last", "jones"));
     SpanQuery q = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "last") }, 0, true);
     Check(q, new int[] { 1, 2 });
     q = new SpanNearQuery(new SpanQuery[] { new FieldMaskingSpanQuery(q1, "last"), new FieldMaskingSpanQuery(q2, "last") }, 0, true);
     Check(q, new int[] { 1, 2 });
 }
 public virtual void TestNoop0()
 {
     SpanQuery q1 = new SpanTermQuery(new Term("last", "sally"));
     SpanQuery q = new FieldMaskingSpanQuery(q1, "first");
     Check(q, new int[] { }); // :EMPTY:
 }
예제 #38
0
        public virtual void TestSpanWithMultipleNotSingle()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "eight"));
            SpanTermQuery term2 = new SpanTermQuery(new Term("field", "one"));
            SpanNearQuery near = new SpanNearQuery(new SpanQuery[] { term1, term2 }, 4, true);
            SpanTermQuery term3 = new SpanTermQuery(new Term("field", "forty"));

            SpanOrQuery or = new SpanOrQuery(term3);

            SpanNotQuery query = new SpanNotQuery(near, or);

            CheckHits(query, new int[] { 801, 821, 831, 851, 861, 871, 881, 891, 1801, 1821, 1831, 1851, 1861, 1871, 1881, 1891 });

            Assert.IsTrue(Searcher.Explain(query, 801).Value > 0.0f);
            Assert.IsTrue(Searcher.Explain(query, 891).Value > 0.0f);
        }
 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
 {
     InitBlock(reader, enclosingInstance);
 }
예제 #40
0
        private int SpanCount(string include, string exclude, int pre, int post)
        {
            SpanTermQuery iq = new SpanTermQuery(new Term(field, include));
            SpanTermQuery eq = new SpanTermQuery(new Term(field, exclude));
            SpanNotQuery snq = new SpanNotQuery(iq, eq, pre, post);
            Spans spans = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, snq);

            int i = 0;
            while (spans.Next())
            {
                i++;
            }
            return i;
        }
 private void InitBlock(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
 {
     this.reader = reader;
     this.enclosingInstance = enclosingInstance;
     positions = reader.TermPositions(Enclosing_Instance.term);
 }
예제 #42
0
 private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
     positions = reader.TermPositions(Enclosing_Instance.term);
 }
 public virtual void TestSimple2()
 {
     AssumeTrue("Broken scoring: LUCENE-3723", Searcher.Similarity is TFIDFSimilarity);
     SpanQuery q1 = new SpanTermQuery(new Term("gender", "female"));
     SpanQuery q2 = new SpanTermQuery(new Term("last", "smith"));
     SpanQuery q = new SpanNearQuery(new SpanQuery[] { q1, new FieldMaskingSpanQuery(q2, "gender") }, -1, false);
     Check(q, new int[] { 2, 4 });
     q = new SpanNearQuery(new SpanQuery[] { new FieldMaskingSpanQuery(q1, "id"), new FieldMaskingSpanQuery(q2, "id") }, -1, false);
     Check(q, new int[] { 2, 4 });
 }
예제 #44
0
		public virtual void  TestSpanNearExact()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "seventy"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "seven"));
			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{term1, term2}, 0, true);
			CheckHits(query, new int[]{77, 177, 277, 377, 477, 577, 677, 777, 877, 977});
			
			Assert.IsTrue(searcher.Explain(query, 77).GetValue() > 0.0f);
			Assert.IsTrue(searcher.Explain(query, 977).GetValue() > 0.0f);
		}
예제 #45
0
 /// <summary> Tests two span queries.
 /// 
 /// </summary>
 /// <throws>  IOException </throws>
 protected internal virtual void  doTestBooleanQueryWithSpanQueries(IndexSearcher s, float expectedScore)
 {
     
     Query spanQuery = new SpanTermQuery(new Term(FIELD_TEXT, "work"));
     BooleanQuery query = new BooleanQuery();
     query.Add(spanQuery, Occur.MUST);
     query.Add(spanQuery, Occur.MUST);
     System.String[] expectedIds = new System.String[]{"1", "2", "3", "4"};
     float[] expectedScores = new float[]{expectedScore, expectedScore, expectedScore, expectedScore};
     assertHits(s, query, "two span queries", expectedIds, expectedScores);
 }
        public virtual void TestSpans0()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("gender", "female"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery q = new SpanOrQuery(q1, new FieldMaskingSpanQuery(q2, "gender"));
            Check(q, new int[] { 0, 1, 2, 3, 4 });

            Spans span = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, q);

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(0, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(1, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(1, 1, 2), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 1, 2), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 2, 3), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(3, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(4, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(4, 1, 2), s(span));

            Assert.AreEqual(false, span.Next());
        }
예제 #47
0
        public virtual void TestSpanTermQuery()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy"));

            CheckHits(term1, new int[] { 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1170, 1270, 1370, 1470, 1570, 1670, 1770, 1870, 1970, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979 });
        }
예제 #48
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);
		}
예제 #49
0
 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanTermQuery enclosingInstance)
 {
     InitBlock(reader, enclosingInstance);
 }
예제 #50
0
 public virtual void TestSpanTermQuery()
 {
     SpanTermQuery term1 = new SpanTermQuery(new Term("field", "seventy"));
     CheckHits(term1, new int[] { 70, 71, 72, 73, 74, 75, 76, 77, 78, 79, 170, 171, 172, 173, 174, 175, 176, 177, 178, 179, 270, 271, 272, 273, 274, 275, 276, 277, 278, 279, 370, 371, 372, 373, 374, 375, 376, 377, 378, 379, 470, 471, 472, 473, 474, 475, 476, 477, 478, 479, 570, 571, 572, 573, 574, 575, 576, 577, 578, 579, 670, 671, 672, 673, 674, 675, 676, 677, 678, 679, 770, 771, 772, 773, 774, 775, 776, 777, 778, 779, 870, 871, 872, 873, 874, 875, 876, 877, 878, 879, 970, 971, 972, 973, 974, 975, 976, 977, 978, 979, 1070, 1071, 1072, 1073, 1074, 1075, 1076, 1077, 1078, 1079, 1170, 1270, 1370, 1470, 1570, 1670, 1770, 1870, 1970, 1171, 1172, 1173, 1174, 1175, 1176, 1177, 1178, 1179, 1271, 1272, 1273, 1274, 1275, 1276, 1277, 1278, 1279, 1371, 1372, 1373, 1374, 1375, 1376, 1377, 1378, 1379, 1471, 1472, 1473, 1474, 1475, 1476, 1477, 1478, 1479, 1571, 1572, 1573, 1574, 1575, 1576, 1577, 1578, 1579, 1671, 1672, 1673, 1674, 1675, 1676, 1677, 1678, 1679, 1771, 1772, 1773, 1774, 1775, 1776, 1777, 1778, 1779, 1871, 1872, 1873, 1874, 1875, 1876, 1877, 1878, 1879, 1971, 1972, 1973, 1974, 1975, 1976, 1977, 1978, 1979 });
 }
        public virtual void TestSpans1()
        {
            SpanQuery q1 = new SpanTermQuery(new Term("first", "sally"));
            SpanQuery q2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery qA = new SpanOrQuery(q1, q2);
            SpanQuery qB = new FieldMaskingSpanQuery(qA, "id");

            Check(qA, new int[] { 0, 1, 2, 4 });
            Check(qB, new int[] { 0, 1, 2, 4 });

            Spans spanA = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, qA);
            Spans spanB = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, qB);

            while (spanA.Next())
            {
                Assert.IsTrue(spanB.Next(), "spanB not still going");
                Assert.AreEqual(s(spanA), s(spanB), "spanA not equal spanB");
            }
            Assert.IsTrue(!(spanB.Next()), "spanB still going even tough spanA is done");
        }
예제 #52
0
		public virtual void  TestSpanComplex1()
		{
			
			SpanTermQuery t1 = new SpanTermQuery(new Term("Field", "six"));
			SpanTermQuery t2 = new SpanTermQuery(new Term("Field", "hundred"));
			SpanNearQuery tt1 = new SpanNearQuery(new SpanQuery[]{t1, t2}, 0, true);
			
			SpanTermQuery t3 = new SpanTermQuery(new Term("Field", "seven"));
			SpanTermQuery t4 = new SpanTermQuery(new Term("Field", "hundred"));
			SpanNearQuery tt2 = new SpanNearQuery(new SpanQuery[]{t3, t4}, 0, true);
			
			SpanTermQuery t5 = new SpanTermQuery(new Term("Field", "seven"));
			SpanTermQuery t6 = new SpanTermQuery(new Term("Field", "six"));
			
			SpanOrQuery to1 = new SpanOrQuery(new SpanQuery[]{tt1, tt2});
			SpanOrQuery to2 = new SpanOrQuery(new SpanQuery[]{t5, t6});
			
			SpanNearQuery query = new SpanNearQuery(new SpanQuery[]{to1, to2}, 100, true);
			
			CheckHits(query, new int[]{606, 607, 626, 627, 636, 637, 646, 647, 656, 657, 666, 667, 676, 677, 686, 687, 696, 697, 706, 707, 726, 727, 736, 737, 746, 747, 756, 757, 766, 767, 776, 777, 786, 787, 796, 797});
		}
        public virtual void TestSpans2()
        {
            AssumeTrue("Broken scoring: LUCENE-3723", Searcher.Similarity is TFIDFSimilarity);
            SpanQuery qA1 = new SpanTermQuery(new Term("gender", "female"));
            SpanQuery qA2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery qA = new SpanOrQuery(qA1, new FieldMaskingSpanQuery(qA2, "gender"));
            SpanQuery qB = new SpanTermQuery(new Term("last", "jones"));
            SpanQuery q = new SpanNearQuery(new SpanQuery[] { new FieldMaskingSpanQuery(qA, "id"), new FieldMaskingSpanQuery(qB, "id") }, -1, false);
            Check(q, new int[] { 0, 1, 2, 3 });

            Spans span = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, q);

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(0, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(1, 1, 2), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 0, 1), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(2, 2, 3), s(span));

            Assert.AreEqual(true, span.Next());
            Assert.AreEqual(s(3, 0, 1), s(span));

            Assert.AreEqual(false, span.Next());
        }
예제 #54
0
		public virtual void  TestSpanNot()
		{
			SpanTermQuery term1 = new SpanTermQuery(new Term("Field", "eight"));
			SpanTermQuery term2 = new SpanTermQuery(new Term("Field", "one"));
			SpanNearQuery near = new SpanNearQuery(new SpanQuery[]{term1, term2}, 4, true);
			SpanTermQuery term3 = new SpanTermQuery(new Term("Field", "forty"));
			SpanNotQuery query = new SpanNotQuery(near, term3);
			
			CheckHits(query, new int[]{801, 821, 831, 851, 861, 871, 881, 891});
			
			Assert.IsTrue(searcher.Explain(query, 801).GetValue() > 0.0f);
			Assert.IsTrue(searcher.Explain(query, 891).GetValue() > 0.0f);
		}