当前位置: 首页>>代码示例>>C#>>正文


C# Spans.SpanNearQuery类代码示例

本文整理汇总了C#中Lucene.Net.Search.Spans.SpanNearQuery的典型用法代码示例。如果您正苦于以下问题:C# SpanNearQuery类的具体用法?C# SpanNearQuery怎么用?C# SpanNearQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


SpanNearQuery类属于Lucene.Net.Search.Spans命名空间,在下文中一共展示了SpanNearQuery类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: TestSpanRegexBug

        public void TestSpanRegexBug()
        {
            CreateRamDirectories();

            SpanRegexQuery srq = new SpanRegexQuery(new Term("field", "a.*"));
            SpanRegexQuery stq = new SpanRegexQuery(new Term("field", "b.*"));
            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { srq, stq }, 6,
                true);

            // 1. Search the same store which works
            IndexSearcher[] arrSearcher = new IndexSearcher[2];
            arrSearcher[0] = new IndexSearcher(indexStoreA, true);
            arrSearcher[1] = new IndexSearcher(indexStoreB, true);
            MultiSearcher searcher = new MultiSearcher(arrSearcher);
            int numHits = searcher.Search(query, null, 1000).TotalHits;
            arrSearcher[0].Close();
            arrSearcher[1].Close();

            // Will fail here
            // We expect 2 but only one matched
            // The rewriter function only write it once on the first IndexSearcher
            // So it's using term: a1 b1 to search on the second IndexSearcher
            // As a result, it won't match the document in the second IndexSearcher
            Assert.AreEqual(2, numHits);
            indexStoreA.Close();
            indexStoreB.Close();
        }
开发者ID:hanabi1224,项目名称:lucene.net,代码行数:27,代码来源:TestSpanRegexQuery.cs

示例2: SpanRegexQueryNrHits

        private int SpanRegexQueryNrHits(String regex1, String regex2, int slop, bool ordered)
        {
            SpanRegexQuery srq1 = new SpanRegexQuery(NewTerm(regex1));
            SpanRegexQuery srq2 = new SpanRegexQuery(NewTerm(regex2));
            SpanNearQuery query = new SpanNearQuery(new SpanQuery[] { srq1, srq2 }, slop, ordered);

            return searcher.Search(query, null, 1000).TotalHits;
        }
开发者ID:raol,项目名称:lucene.net,代码行数:8,代码来源:TestRegexQuery.cs

示例3: TestSpanNearInOrderVersusOutOfOrder

 public virtual void TestSpanNearInOrderVersusOutOfOrder()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, 3, true);
     SpanNearQuery q2 = new SpanNearQuery(subquery, 3, false);
     AssertSubsetOf(q1, q2);
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:9,代码来源:TestSpanSearchEquivalence.cs

示例4: OrderedSlopTest3

		public virtual void  OrderedSlopTest3(int slop, int[] expectedDocs)
		{
			SpanTermQuery w1 = makeSpanTermQuery("w1");
			SpanTermQuery w2 = makeSpanTermQuery("w2");
			SpanTermQuery w3 = makeSpanTermQuery("w3");
			bool ordered = true;
			SpanNearQuery snq = new SpanNearQuery(new SpanQuery[]{w1, w2, w3}, slop, ordered);
			CheckHits(snq, expectedDocs);
		}
开发者ID:emtees,项目名称:old-code,代码行数:9,代码来源:TestSpans.cs

示例5: TestSpanNearVersusBooleanAnd

 public virtual void TestSpanNearVersusBooleanAnd()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, int.MaxValue, false);
     BooleanQuery q2 = new BooleanQuery();
     q2.Add(new TermQuery(t1), Occur.MUST);
     q2.Add(new TermQuery(t2), Occur.MUST);
     AssertSameSet(q1, q2);
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:11,代码来源:TestSpanSearchEquivalence.cs

示例6: TestSpanNearVersusPhrase

 public virtual void TestSpanNearVersusPhrase()
 {
     Term t1 = RandomTerm();
     Term t2 = RandomTerm();
     SpanQuery[] subquery = new SpanQuery[] { new SpanTermQuery(t1), new SpanTermQuery(t2) };
     SpanNearQuery q1 = new SpanNearQuery(subquery, 0, true);
     PhraseQuery q2 = new PhraseQuery();
     q2.Add(t1);
     q2.Add(t2);
     AssertSameSet(q1, q2);
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:11,代码来源:TestSpanSearchEquivalence.cs

示例7: NearSpansUnordered

        private int totalLength; // sum of current lengths

        #endregion Fields

        #region Constructors

        public NearSpansUnordered(SpanNearQuery query, IndexReader reader)
        {
            this.query = query;
            this.slop = query.GetSlop();

            SpanQuery[] clauses = query.GetClauses();
            queue = new CellQueue(this, clauses.Length);
            for (int i = 0; i < clauses.Length; i++)
            {
                SpansCell cell = new SpansCell(this, clauses[i].GetPayloadSpans(reader), i);
                ordered.Add(cell);
            }
        }
开发者ID:cqm0609,项目名称:lucene-file-finder,代码行数:19,代码来源:NearSpansUnordered.cs

示例8: NearSpansOrdered

 public NearSpansOrdered(SpanNearQuery spanNearQuery, IndexReader reader)
 {
     InitBlock();
     if (spanNearQuery.GetClauses().Length < 2)
     {
         throw new System.ArgumentException("Less than 2 clauses: " + spanNearQuery);
     }
     allowedSlop = spanNearQuery.GetSlop();
     SpanQuery[] clauses = spanNearQuery.GetClauses();
     subSpans = new PayloadSpans[clauses.Length];
     matchPayload = new List<byte[]>();
     subSpansByDoc = new PayloadSpans[clauses.Length];
     for (int i = 0; i < clauses.Length; i++)
     {
         subSpans[i] = clauses[i].GetPayloadSpans(reader);
         subSpansByDoc[i] = subSpans[i]; // used in toSameDoc()
     }
     query = spanNearQuery; // kept for toString() only.
 }
开发者ID:cqm0609,项目名称:lucene-file-finder,代码行数:19,代码来源:NearSpansOrdered.cs

示例9: BasicSpanQuery

        public void BasicSpanQuery()
        {
            Initialize();

            // Builds a query that search for two sets of terms that should
            // be close to eachother in the text that is being indexed.
            // Please note, the distance between the two sets doesn't need to be short.
            // As long as there's a quick fox of a non-descript color and a lazy dog we're happy.
            SpanNearQuery nearQuery = new SpanNearQuery(
                new[]
                {
                    // The terms quick and fox must be close to eachother
                    new SpanNearQuery(new[]
                    {
                        new SpanTermQuery(new Term("text","quick")),
                        new SpanTermQuery(new Term("text","fox"))
                    },2,true),

                    // The terms lazy and dog should also be close to eachother.
                    new SpanNearQuery(new[]
                    {
                        new SpanTermQuery(new Term("text","lazy")),
                        new SpanTermQuery(new Term("text","dog"))
                    },1,true)
                },Int16.MaxValue,false);

            using (var reader = IndexReader.Open(_directory, true))
            {
                var searcher = new IndexSearcher(reader);
                var results = searcher.Search(nearQuery,null,Int16.MaxValue);

                foreach (var doc in results.ScoreDocs)
                {
                    var document = reader.Document(doc.Doc);

                    Trace.WriteLine(string.Format("{0} (rank : {1})",document.Get("text"),doc.Score));
                }
            }
        }
开发者ID:wmeints,项目名称:Presentations,代码行数:39,代码来源:SpanQueryTestFixture.cs

示例10: TestSpanComplex1

		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});
		}
开发者ID:emtees,项目名称:old-code,代码行数:21,代码来源:TestBasics.cs

示例11: TestSpanExactNested

		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);
		}
开发者ID:emtees,项目名称:old-code,代码行数:15,代码来源:TestBasics.cs

示例12: TestSpanScorerZeroSloppyFreq

        public virtual void TestSpanScorerZeroSloppyFreq()
        {
            bool ordered = true;
            int slop = 1;
            IndexReaderContext topReaderContext = Searcher.TopReaderContext;
            IList<AtomicReaderContext> leaves = topReaderContext.Leaves;
            int subIndex = ReaderUtil.SubIndex(11, leaves);
            for (int i = 0, c = leaves.Count; i < c; i++)
            {
                AtomicReaderContext ctx = leaves[i];

                Similarity sim = new DefaultSimilarityAnonymousInnerClassHelper(this);

                Similarity oldSim = Searcher.Similarity;
                Scorer spanScorer;
                try
                {
                    Searcher.Similarity = sim;
                    SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2") }, slop, ordered);

                    spanScorer = Searcher.CreateNormalizedWeight(snq).Scorer(ctx, ((AtomicReader)ctx.Reader).LiveDocs);
                }
                finally
                {
                    Searcher.Similarity = oldSim;
                }
                if (i == subIndex)
                {
                    Assert.IsTrue(spanScorer.NextDoc() != DocIdSetIterator.NO_MORE_DOCS, "first doc");
                    Assert.AreEqual(spanScorer.DocID() + ctx.DocBase, 11, "first doc number");
                    float score = spanScorer.Score();
                    Assert.IsTrue(score == 0.0f, "first doc score should be zero, " + score);
                }
                else
                {
                    Assert.IsTrue(spanScorer.NextDoc() == DocIdSetIterator.NO_MORE_DOCS, "no second doc");
                }
            }
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:39,代码来源:TestSpans.cs

示例13: TestSpanNearOrderedOverlap

        public virtual void TestSpanNearOrderedOverlap()
        {
            bool ordered = true;
            int slop = 1;
            SpanNearQuery snq = new SpanNearQuery(new SpanQuery[] { MakeSpanTermQuery("t1"), MakeSpanTermQuery("t2"), MakeSpanTermQuery("t3") }, slop, ordered);
            Spans spans = MultiSpansWrapper.Wrap(Searcher.TopReaderContext, snq);

            Assert.IsTrue(spans.Next(), "first range");
            Assert.AreEqual(11, spans.Doc(), "first doc");
            Assert.AreEqual(0, spans.Start(), "first start");
            Assert.AreEqual(4, spans.End(), "first end");

            Assert.IsTrue(spans.Next(), "second range");
            Assert.AreEqual(11, spans.Doc(), "second doc");
            Assert.AreEqual(2, spans.Start(), "second start");
            Assert.AreEqual(6, spans.End(), "second end");

            Assert.IsFalse(spans.Next(), "third range");
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:19,代码来源:TestSpans.cs

示例14: TestSpans2

        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());
        }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:29,代码来源:TestFieldMaskingSpanQuery.cs

示例15: TestNoop1

 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 });
 }
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:9,代码来源:TestFieldMaskingSpanQuery.cs


注:本文中的Lucene.Net.Search.Spans.SpanNearQuery类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。