Beispiel #1
0
        public virtual void TestComplexSpanChecks()
        {
            SpanTermQuery one   = new SpanTermQuery(new Term("field", "one"));
            SpanTermQuery thous = new SpanTermQuery(new Term("field", "thousand"));
            //should be one position in between
            SpanTermQuery hundred = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery three   = new SpanTermQuery(new Term("field", "three"));

            SpanNearQuery oneThous         = new SpanNearQuery(new SpanQuery[] { one, thous }, 0, true);
            SpanNearQuery hundredThree     = new SpanNearQuery(new SpanQuery[] { hundred, three }, 0, true);
            SpanNearQuery oneThousHunThree = new SpanNearQuery(new SpanQuery[] { oneThous, hundredThree }, 1, true);
            SpanQuery     query;

            //this one's too small
            query = new SpanPositionRangeQuery(oneThousHunThree, 1, 2);
            CheckHits(query, new int[] { });
            //this one's just right
            query = new SpanPositionRangeQuery(oneThousHunThree, 0, 6);
            CheckHits(query, new int[] { 1103, 1203, 1303, 1403, 1503, 1603, 1703, 1803, 1903 });

            var      payloads = new List <byte[]>();
            BytesRef pay      = new BytesRef(("pos: " + 0).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay2     = new BytesRef(("pos: " + 1).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay3     = new BytesRef(("pos: " + 3).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay4     = new BytesRef(("pos: " + 4).GetBytes(IOUtils.CHARSET_UTF_8));

            payloads.Add(pay.Bytes);
            payloads.Add(pay2.Bytes);
            payloads.Add(pay3.Bytes);
            payloads.Add(pay4.Bytes);
            query = new SpanNearPayloadCheckQuery(oneThousHunThree, payloads);
            CheckHits(query, new int[] { 1103, 1203, 1303, 1403, 1503, 1603, 1703, 1803, 1903 });
        }
Beispiel #2
0
        public override object Clone()
        {
            SpanNearPayloadCheckQuery result = new SpanNearPayloadCheckQuery((SpanNearQuery)m_match.Clone(), m_payloadToMatch);

            result.Boost = Boost;
            return(result);
        }
Beispiel #3
0
        public virtual void TestSpanPayloadCheck()
        {
            SpanTermQuery term1 = new SpanTermQuery(new Term("field", "five"));

#pragma warning disable 612, 618
            BytesRef pay = new BytesRef(("pos: " + 5).GetBytes(IOUtils.CHARSET_UTF_8));
#pragma warning restore 612, 618
            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);
#pragma warning disable 612, 618
            pay  = new BytesRef(("pos: " + 0).GetBytes(IOUtils.CHARSET_UTF_8));
            pay2 = new BytesRef(("pos: " + 1).GetBytes(IOUtils.CHARSET_UTF_8));
#pragma warning restore 612, 618
            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);
#pragma warning disable 612, 618
            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));
#pragma warning restore 612, 618
            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 });
        }
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is SpanNearPayloadCheckQuery))
            {
                return(false);
            }

            SpanNearPayloadCheckQuery other = (SpanNearPayloadCheckQuery)o;

            return(this.PayloadToMatch.Equals(other.PayloadToMatch) && this.match.Equals(other.match) && this.Boost == other.Boost);
        }
Beispiel #5
0
        public override bool Equals(object o)
        {
            if (this == o)
            {
                return(true);
            }
            if (!(o is SpanNearPayloadCheckQuery))
            {
                return(false);
            }

            SpanNearPayloadCheckQuery other = (SpanNearPayloadCheckQuery)o;

            // LUCENENET NOTE: Need to call Collections.Equals() to compare equality of all contained values
            return(Collections.Equals(this.m_payloadToMatch, other.m_payloadToMatch) &&
                   this.m_match.Equals(other.m_match) &&
                   this.Boost == other.Boost);
        }
Beispiel #6
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 });
        }
Beispiel #7
0
        public virtual void TestComplexSpanChecks()
        {
            SpanTermQuery one = new SpanTermQuery(new Term("field", "one"));
            SpanTermQuery thous = new SpanTermQuery(new Term("field", "thousand"));
            //should be one position in between
            SpanTermQuery hundred = new SpanTermQuery(new Term("field", "hundred"));
            SpanTermQuery three = new SpanTermQuery(new Term("field", "three"));

            SpanNearQuery oneThous = new SpanNearQuery(new SpanQuery[] { one, thous }, 0, true);
            SpanNearQuery hundredThree = new SpanNearQuery(new SpanQuery[] { hundred, three }, 0, true);
            SpanNearQuery oneThousHunThree = new SpanNearQuery(new SpanQuery[] { oneThous, hundredThree }, 1, true);
            SpanQuery query;
            //this one's too small
            query = new SpanPositionRangeQuery(oneThousHunThree, 1, 2);
            CheckHits(query, new int[] { });
            //this one's just right
            query = new SpanPositionRangeQuery(oneThousHunThree, 0, 6);
            CheckHits(query, new int[] { 1103, 1203, 1303, 1403, 1503, 1603, 1703, 1803, 1903 });

            var payloads = new List<byte[]>();
            BytesRef pay = new BytesRef(("pos: " + 0).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay2 = new BytesRef(("pos: " + 1).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay3 = new BytesRef(("pos: " + 3).GetBytes(IOUtils.CHARSET_UTF_8));
            BytesRef pay4 = new BytesRef(("pos: " + 4).GetBytes(IOUtils.CHARSET_UTF_8));
            payloads.Add(pay.Bytes);
            payloads.Add(pay2.Bytes);
            payloads.Add(pay3.Bytes);
            payloads.Add(pay4.Bytes);
            query = new SpanNearPayloadCheckQuery(oneThousHunThree, payloads);
            CheckHits(query, new int[] { 1103, 1203, 1303, 1403, 1503, 1603, 1703, 1803, 1903 });
        }
 public override object Clone()
 {
     SpanNearPayloadCheckQuery result = new SpanNearPayloadCheckQuery((SpanNearQuery)match.Clone(), PayloadToMatch);
     result.Boost = Boost;
     return result;
 }