本文整理汇总了C#中Lucene.Net.Search.Spans.SpanNearQuery类的典型用法代码示例。如果您正苦于以下问题:C# SpanNearQuery类的具体用法?C# SpanNearQuery怎么用?C# SpanNearQuery使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
SpanNearQuery类属于Lucene.Net.Search.Spans命名空间,在下文中一共展示了SpanNearQuery类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的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
示例16: TestSpanWithMultipleNotSingle
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);
}
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:16,代码来源:TestBasics.cs
示例17: TestSpanPayloadCheck
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 });
}
开发者ID:WakeflyCBass,项目名称:lucenenet,代码行数:39,代码来源:TestBasics.cs
示例18: VisitQuery
private static void VisitQuery(SpanNearQuery query, AzureQueryLogger.IndentedTextWriter writer)
{
writer.WriteLine("IsInOrder: {0}", (query.IsInOrder ? 1 : 0));
writer.WriteLine("Slop: {0}", (object)query.Slop);
AzureQueryLogger.VisitClauses(writer, query.GetClauses());
}
开发者ID:jscott1277,项目名称:SitecoreAzureSearchProvider,代码行数:6,代码来源:AzureQueryLogger.cs
示例19: GetTermsFromSpanNearQuery
private static void GetTermsFromSpanNearQuery(SpanNearQuery query, HashSetSupport terms, string fieldName)
{
ICollection queryTerms = query.GetTerms();
for (IEnumerator iterator = queryTerms.GetEnumerator(); iterator.MoveNext(); )
{
// break it out for debugging.
Term term = (Term) iterator.Current;
string text = term.Text();
if ((fieldName == null) || (term.Field() == (string)(object)fieldName))
{
terms.Add(new WeightedTerm(query.GetBoost(), text));
}
}
}
开发者ID:usmanghani,项目名称:Misc,代码行数:16,代码来源:QueryTermExtractor.cs
示例20: TestSimple1
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 });
}
开发者ID:Cefa68000,项目名称:lucenenet,代码行数:13,代码来源:TestFieldMaskingSpanQuery.cs
注:本文中的Lucene.Net.Search.Spans.SpanNearQuery类示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论