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());
        }
        public virtual void  TestSpans2()
        {
            SpanQuery qA1 = new SpanTermQuery(new Term("gender", "female"));
            SpanQuery qA2 = new SpanTermQuery(new Term("first", "james"));
            SpanQuery qA  = new SpanOrQuery(new SpanQuery[] { 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 = 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, 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());
        }
        public override Query Rewrite(IndexReader reader)
        {
            SpanOrQuery clone = null;

            for (int i = 0; i < clauses.Count; i++)
            {
                SpanQuery c     = (SpanQuery)clauses[i];
                SpanQuery query = (SpanQuery)c.Rewrite(reader);
                if (query != c)
                {
                    // clause rewrote: must clone
                    if (clone == null)
                    {
                        clone = (SpanOrQuery)this.Clone();
                    }
                    clone.clauses[i] = query;
                }
            }
            if (clone != null)
            {
                return(clone);                // some clauses rewrote
            }
            else
            {
                return(this);                // no clauses rewrote
            }
        }
Beispiel #4
0
        public virtual void TestNoSuchMultiTermsInOr()
        {
            //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"));
            SpanOrQuery near = new SpanOrQuery(new SpanQuery[] { term, spanNoSuch });
            Assert.AreEqual(1, searcher.Search(near, 10).TotalHits);

            //flip
            near = new SpanOrQuery(new SpanQuery[] { spanNoSuch, term });
            Assert.AreEqual(1, searcher.Search(near, 10).TotalHits);

            WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(wcNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanWCNoSuch });
            Assert.AreEqual(1, searcher.Search(near, 10).TotalHits);

            RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(rgxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanRgxNoSuch });
            Assert.AreEqual(1, searcher.Search(near, 10).TotalHits);

            PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(prfxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanPrfxNoSuch });
            Assert.AreEqual(1, searcher.Search(near, 10).TotalHits);

            near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch });
            Assert.AreEqual(0, searcher.Search(near, 10).TotalHits);

            near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch });
            Assert.AreEqual(0, searcher.Search(near, 10).TotalHits);
        }
Beispiel #5
0
 public SpansAnonymousInnerClassHelper(SpanOrQuery outerInstance, AtomicReaderContext context, IBits acceptDocs, IDictionary <Term, TermContext> termContexts)
 {
     this.outerInstance = outerInstance;
     this.context       = context;
     this.acceptDocs    = acceptDocs;
     this.termContexts  = termContexts;
     queue = null;
 }
Beispiel #6
0
        public virtual void  TestSpanOrEmpty()
        {
            Spans spans = OrSpans(new System.String[0]);

            Assert.IsFalse(spans.Next(), "empty next");

            SpanOrQuery a = new SpanOrQuery(new SpanQuery[0]);
            SpanOrQuery b = new SpanOrQuery(new SpanQuery[0]);

            Assert.IsTrue(a.Equals(b), "empty should equal");
        }
Beispiel #7
0
        public virtual void TestSpanOrVersusBoolean()
        {
            Term         t1 = RandomTerm();
            Term         t2 = RandomTerm();
            BooleanQuery q1 = new BooleanQuery();

            q1.Add(new TermQuery(t1), Occur.SHOULD);
            q1.Add(new TermQuery(t2), Occur.SHOULD);
            SpanOrQuery q2 = new SpanOrQuery(new SpanTermQuery(t1), new SpanTermQuery(t2));

            AssertSameSet(q1, q2);
        }
Beispiel #8
0
 private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
     all   = new System.Collections.ArrayList(Enclosing_Instance.clauses.Count);
     queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
     System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
     while (i.MoveNext())
     {
         // initialize all
         all.Add(((SpanQuery)i.Current).GetSpans(reader));
     }
 }
Beispiel #9
0
			private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
			{
				this.reader = reader;
				this.enclosingInstance = enclosingInstance;
				all = new System.Collections.ArrayList(Enclosing_Instance.clauses.Count);
				queue = new SpanQueue(enclosingInstance, Enclosing_Instance.clauses.Count);
				System.Collections.IEnumerator i = Enclosing_Instance.clauses.GetEnumerator();
				while (i.MoveNext())
				{
					// initialize all
					all.Add(((SpanQuery) i.Current).GetSpans(reader));
				}
			}
Beispiel #10
0
        public override System.Object Clone()
        {
            int sz = clauses.Count;
            SpanQuery[] newClauses = new SpanQuery[sz];

            for (int i = 0; i < sz; i++)
            {
                SpanQuery clause = (SpanQuery) clauses[i];
                newClauses[i] = (SpanQuery) clause.Clone();
            }
            SpanOrQuery soq = new SpanOrQuery(newClauses);
            soq.SetBoost(GetBoost());
            return soq;
        }
Beispiel #11
0
        public override object Clone()
        {
            int sz = clauses.Count;

            SpanQuery[] newClauses = new SpanQuery[sz];

            for (int i = 0; i < sz; i++)
            {
                newClauses[i] = (SpanQuery)clauses[i].Clone();
            }
            SpanOrQuery soq = new SpanOrQuery(newClauses);

            soq.Boost = Boost;
            return(soq);
        }
Beispiel #12
0
        public virtual void TestSpanNearOr()
        {
            SpanTermQuery t1 = new SpanTermQuery(new Term("field", "six"));
            SpanTermQuery t3 = new SpanTermQuery(new Term("field", "seven"));

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

            SpanOrQuery to1 = new SpanOrQuery(t1, t3);
            SpanOrQuery to2 = new SpanOrQuery(t5, t6);

            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { to1, to2 }, 10, 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 });
        }
Beispiel #13
0
        public override System.Object Clone()
        {
            int sz = clauses.Count;

            SpanQuery[] newClauses = new SpanQuery[sz];

            for (int i = 0; i < sz; i++)
            {
                SpanQuery clause = (SpanQuery)clauses[i];
                newClauses[i] = (SpanQuery)clause.Clone();
            }
            SpanOrQuery soq = new SpanOrQuery(newClauses);

            soq.SetBoost(GetBoost());
            return(soq);
        }
Beispiel #14
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);
        }
Beispiel #15
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);
        }
Beispiel #16
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);
        }
Beispiel #17
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, null).Value > 0.0f);
            Assert.IsTrue(searcher.Explain(query, 891, null).Value > 0.0f);
        }
        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");
        }
        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");
        }
Beispiel #20
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 });
        }
Beispiel #21
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || this.GetType() != o.GetType())
            {
                return(false);
            }

            SpanOrQuery that = (SpanOrQuery)o;

            if (!clauses.Equals(that.clauses))
            {
                return(false);
            }

            return(Boost == that.Boost);
        }
Beispiel #22
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o is null || this.GetType() != o.GetType())
            {
                return(false);
            }

            SpanOrQuery that = (SpanOrQuery)o;

            if (!clauses.Equals(that.clauses))
            {
                return(false);
            }

            // LUCENENET specific - compare bits rather than using equality operators to prevent these comparisons from failing in x86 in .NET Framework with optimizations enabled
            return(NumericUtils.SingleToSortableInt32(Boost) == NumericUtils.SingleToSortableInt32(that.Boost));
        }
        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());
        }
        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());
        }
Beispiel #25
0
        public override bool Equals(System.Object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            SpanOrQuery that = (SpanOrQuery)o;

            if (!clauses.Equals(that.clauses))
            {
                return(false);
            }
            if (!(clauses.Count == 0) && !field.Equals(that.field))
            {
                return(false);
            }

            return(Boost == that.Boost);
        }
Beispiel #26
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);
            }
        }
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (o == null || GetType() != o.GetType())
            {
                return(false);
            }

            SpanOrQuery that = (SpanOrQuery)o;

            if (!clauses.Equals(that.clauses))
            {
                return(false);
            }
            if (!field.Equals(that.field))
            {
                return(false);
            }

            return(GetBoost() == that.GetBoost());
        }
Beispiel #28
0
        public virtual void TestSpanOrEmpty()
        {
            Spans spans = OrSpans(new string[0]);
            Assert.IsFalse(spans.Next(), "empty next");

            SpanOrQuery a = new SpanOrQuery();
            SpanOrQuery b = new SpanOrQuery();
            Assert.IsTrue(a.Equals(b), "empty should equal");
        }
 public virtual void TestSpanOrVersusBoolean()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     BooleanQuery q1 = new BooleanQuery();
     q1.Add(new TermQuery(t1), Occur.SHOULD);
     q1.Add(new TermQuery(t2), Occur.SHOULD);
     SpanOrQuery q2 = new SpanOrQuery(new SpanTermQuery(t1), new SpanTermQuery(t2));
     AssertSameSet(q1, q2);
 }
 public AnonymousClassPayloadSpans(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
 {
     InitBlock(reader, enclosingInstance);
 }
 private void  InitBlock(SpanOrQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
Beispiel #32
0
 public SpanQueue(SpanOrQuery enclosingInstance, int size)
 {
     InitBlock(enclosingInstance);
     Initialize(size);
 }
        public virtual void TestNoSuchMultiTermsInOr()
        {
            //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"));
            SpanOrQuery near = new SpanOrQuery(new SpanQuery[] { term, spanNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

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

            WildcardQuery wcNoSuch = new WildcardQuery(new Term("field", "noSuch*"));
            SpanQuery spanWCNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(wcNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanWCNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            RegexpQuery rgxNoSuch = new RegexpQuery(new Term("field", "noSuch"));
            SpanQuery spanRgxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(rgxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanRgxNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

            PrefixQuery prfxNoSuch = new PrefixQuery(new Term("field", "noSuch"));
            SpanQuery spanPrfxNoSuch = new SpanMultiTermQueryWrapper<MultiTermQuery>(prfxNoSuch);
            near = new SpanOrQuery(new SpanQuery[] { term, spanPrfxNoSuch });
            Assert.AreEqual(1, Searcher.Search(near, 10).TotalHits);

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

            near = new SpanOrQuery(new SpanQuery[] { spanPrfxNoSuch, spanPrfxNoSuch });
            Assert.AreEqual(0, Searcher.Search(near, 10).TotalHits);
        }
		public virtual void  TestSpans2()
		{
			SpanQuery qA1 = new SpanTermQuery(new Term("gender", "female"));
			SpanQuery qA2 = new SpanTermQuery(new Term("first", "james"));
			SpanQuery qA = new SpanOrQuery(new SpanQuery[]{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 = 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, 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());
		}
			private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
			{
				this.reader = reader;
				this.enclosingInstance = enclosingInstance;
			}
Beispiel #36
0
 public SpanQueue(SpanOrQuery outerInstance, int size)
     : base(size)
 {
     this.outerInstance = outerInstance;
 }
        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());
        }
        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");
        }
        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());
        }
 private static void VisitQuery(SpanOrQuery query, AzureQueryLogger.IndentedTextWriter writer)
 {
     SpanQuery[] clauses = query.GetClauses();
     AzureQueryLogger.VisitClauses(writer, clauses);
 }
Beispiel #41
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);
        }
Beispiel #42
0
 public virtual Query VisitSpanOrQuery(SpanOrQuery spanOrq) { throw new NotImplementedException(); }
Beispiel #43
0
        public virtual void TestSpanNearOr()
        {
            SpanTermQuery t1 = new SpanTermQuery(new Term("field", "six"));
            SpanTermQuery t3 = new SpanTermQuery(new Term("field", "seven"));

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

            SpanOrQuery to1 = new SpanOrQuery(t1, t3);
            SpanOrQuery to2 = new SpanOrQuery(t5, t6);

            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { to1, to2 }, 10, 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 });
        }
Beispiel #44
0
 public AnonymousClassSpans(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
 {
     InitBlock(reader, enclosingInstance);
 }
		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");
		}
Beispiel #46
0
 private void InitBlock(SpanOrQuery enclosingInstance)
 {
     this.enclosingInstance = enclosingInstance;
 }
		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());
		}
            private void AddComplexPhraseClause(List<SpanQuery> spanClauses, BooleanQuery qc)
            {
                List<SpanQuery> ors = new List<SpanQuery>();
                List<SpanQuery> nots = new List<SpanQuery>();
                BooleanClause[] bclauses = qc.Clauses;

                // For all clauses e.g. one* two~
                for (int i = 0; i < bclauses.Length; i++)
                {
                    Query childQuery = bclauses[i].Query;

                    // select the list to which we will add these options
                    List<SpanQuery> chosenList = ors;
                    if (bclauses[i].Occur_ == BooleanClause.Occur.MUST_NOT)
                    {
                        chosenList = nots;
                    }

                    if (childQuery is TermQuery)
                    {
                        TermQuery tq = (TermQuery)childQuery;
                        SpanTermQuery stq = new SpanTermQuery(tq.Term);
                        stq.Boost = tq.Boost;
                        chosenList.Add(stq);
                    }
                    else if (childQuery is BooleanQuery)
                    {
                        BooleanQuery cbq = (BooleanQuery)childQuery;
                        AddComplexPhraseClause(chosenList, cbq);
                    }
                    else
                    {
                        // LUCENETODO alternatively could call extract terms here?
                        throw new ArgumentException("Unknown query type:"
                            + childQuery.GetType().Name);
                    }
                }
                if (ors.Count == 0)
                {
                    return;
                }
                SpanOrQuery soq = new SpanOrQuery(ors
                    .ToArray());
                if (nots.Count == 0)
                {
                    spanClauses.Add(soq);
                }
                else
                {
                    SpanOrQuery snqs = new SpanOrQuery(nots
                        .ToArray());
                    SpanNotQuery snq = new SpanNotQuery(soq, snqs);
                    spanClauses.Add(snq);
                }
            }
Beispiel #49
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 SpanQueue(SpanOrQuery enclosingInstance, int size)
 {
     InitBlock(enclosingInstance);
     Initialize(size);
 }
Beispiel #51
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);
		}
 private void  InitBlock(Lucene.Net.Index.IndexReader reader, SpanOrQuery enclosingInstance)
 {
     this.reader            = reader;
     this.enclosingInstance = enclosingInstance;
 }
Beispiel #53
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);
		}