本文整理汇总了C#中Lucene.Net.Search.MatchAllDocsQuery.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# MatchAllDocsQuery.ToString方法的具体用法?C# MatchAllDocsQuery.ToString怎么用?C# MatchAllDocsQuery.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.MatchAllDocsQuery
的用法示例。
在下文中一共展示了MatchAllDocsQuery.ToString方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestQuery
public virtual void TestQuery()
{
RAMDirectory dir = new RAMDirectory();
IndexWriter iw = new IndexWriter(dir, analyzer, true, IndexWriter.MaxFieldLength.LIMITED);
iw.SetMaxBufferedDocs(2); // force multi-segment
AddDoc("one", iw, 1f);
AddDoc("two", iw, 20f);
AddDoc("three four", iw, 300f);
iw.Close();
IndexReader ir = IndexReader.Open(dir);
IndexSearcher is_Renamed = new IndexSearcher(ir);
ScoreDoc[] hits;
// assert with norms scoring turned off
hits = is_Renamed.Search(new MatchAllDocsQuery(), null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length);
Assert.AreEqual(ir.Document(hits[0].Doc).Get("key"), "one");
Assert.AreEqual(ir.Document(hits[1].Doc).Get("key"), "two");
Assert.AreEqual(ir.Document(hits[2].Doc).Get("key"), "three four");
// assert with norms scoring turned on
MatchAllDocsQuery normsQuery = new MatchAllDocsQuery("key");
hits = is_Renamed.Search(normsQuery, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length);
Assert.AreEqual(ir.Document(hits[0].Doc).Get("key"), "three four");
Assert.AreEqual(ir.Document(hits[1].Doc).Get("key"), "two");
Assert.AreEqual(ir.Document(hits[2].Doc).Get("key"), "one");
// change norm & retest
ir.SetNorm(0, "key", 400f);
normsQuery = new MatchAllDocsQuery("key");
hits = is_Renamed.Search(normsQuery, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length);
Assert.AreEqual(ir.Document(hits[0].Doc).Get("key"), "one");
Assert.AreEqual(ir.Document(hits[1].Doc).Get("key"), "three four");
Assert.AreEqual(ir.Document(hits[2].Doc).Get("key"), "two");
// some artificial queries to trigger the use of skipTo():
BooleanQuery bq = new BooleanQuery();
bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
hits = is_Renamed.Search(bq, null, 1000).ScoreDocs;
Assert.AreEqual(3, hits.Length);
bq = new BooleanQuery();
bq.Add(new MatchAllDocsQuery(), BooleanClause.Occur.MUST);
bq.Add(new TermQuery(new Term("key", "three")), BooleanClause.Occur.MUST);
hits = is_Renamed.Search(bq, null, 1000).ScoreDocs;
Assert.AreEqual(1, hits.Length);
// delete a document:
is_Renamed.GetIndexReader().DeleteDocument(0);
hits = is_Renamed.Search(new MatchAllDocsQuery(), null, 1000).ScoreDocs;
Assert.AreEqual(2, hits.Length);
// test parsable toString()
QueryParser qp = new QueryParser("key", analyzer);
hits = is_Renamed.Search(qp.Parse(new MatchAllDocsQuery().ToString()), null, 1000).ScoreDocs;
Assert.AreEqual(2, hits.Length);
// test parsable toString() with non default boost
Query maq = new MatchAllDocsQuery();
maq.SetBoost(2.3f);
Query pq = qp.Parse(maq.ToString());
hits = is_Renamed.Search(pq, null, 1000).ScoreDocs;
Assert.AreEqual(2, hits.Length);
is_Renamed.Close();
ir.Close();
dir.Close();
}
示例2: TestRangeFacetHandler
public void TestRangeFacetHandler()
{
var query = new MatchAllDocsQuery();
Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
var testRangeFacetHandlers = new List<IFacetHandler>();
//testRangeFacetHandlers.Add(new RangeFacetHandler("year", true));//auto range // NightOwl888 - Auto range is no longer a feature.
testRangeFacetHandlers.Add(new RangeFacetHandler("year", new List<string>(new string[] { "[* TO 2000]", "[2000 TO 2005]", "[2006 TO 2010]", "[2011 TO *]" })));
//testRangeFacetHandlers.Add(new RangeFacetHandler("price", "price", new NumberFieldFactory(), true)); // NightOwl888 - Auto range is no longer a feature.
for (var i = 0; i < testRangeFacetHandlers.Count; i++)
{
var request = new BrowseRequest()
{
Count = 100,
Offset = 0,
Query = query,
Sort = new Lucene.Net.Search.Sort(new SortField("price", SortField.DOUBLE, false)).GetSort()
};
var sectionFilter = new BrowseSelection("category");
sectionFilter.NotValues = new string[] { "5" };
sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd;
request.AddSelection(sectionFilter);
var faceHandler = testRangeFacetHandlers[i];
var faceHandlers = new IFacetHandler[] { faceHandler, new SimpleFacetHandler("category") };
var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
request.SetFacetSpec(faceHandler.Name, factSpec);
var result = browser.Browse(request);
Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
foreach (var facet in result.FacetMap[faceHandler.Name].GetFacets())
{
Console.WriteLine(facet.ToString());
}
Console.WriteLine("");
}
}
示例3: TestFacetSelectionFilter
public void TestFacetSelectionFilter()
{
var query = new MatchAllDocsQuery();
Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
var request = new BrowseRequest()
{
Count = 10,
Offset = 0,
Query = query
};
var authors = new string[] { "kathy", "sierra" };//kathy&sierra
var sectionFilter = new BrowseSelection("author");
sectionFilter.Values = authors;
sectionFilter.SelectionOperation = BrowseSelection.ValueOperation.ValueOperationAnd;
request.AddSelection(sectionFilter);
var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), new IFacetHandler[] { new MultiValueFacetHandler("author") }));
var result = browser.Browse(request);
Console.WriteLine("===========================");
for (var i = 0; i < result.Hits.Length; i++)
{
var doc = browser.Doc(result.Hits[i].DocId);
var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key;
Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue));
}
}
示例4: TestMultiValueFacetHandler
public void TestMultiValueFacetHandler()
{
var query = new MatchAllDocsQuery();
Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
var request = new BrowseRequest()
{
Count = 100,
Offset = 0,
Query = query,
Sort = new Lucene.Net.Search.Sort(new SortField("path", SortField.STRING, false)).GetSort()
};
var faceHandlers = new IFacetHandler[] { new MultiValueFacetHandler("path") };
var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
request.SetFacetSpec("path", factSpec);
var result = browser.Browse(request);
Console.WriteLine(string.Format("total hits:{0}", result.NumHits));
Console.WriteLine("===========================");
foreach (var facet in result.FacetMap["path"].GetFacets())
{
Console.WriteLine(facet.ToString());
}
Console.WriteLine("===========================");
for (var i = 0; i < result.Hits.Length; i++)
{
var doc = browser.Doc(result.Hits[i].DocId);
var category = _categories.First(k => k.Value == int.Parse(doc.GetField("category").StringValue)).Key;
Console.WriteLine(string.Format("{2} - {0} ${1} by {3}", doc.GetField("name").StringValue, doc.GetField("price").StringValue, category, doc.GetField("author").StringValue));
}
}
示例5: TestAutoComplete
public void TestAutoComplete()
{
var query = new MatchAllDocsQuery();
Console.WriteLine(string.Format("query: <{0}>", query.ToString()));
var request = new BrowseRequest()
{
Count = 10,
Offset = 0,
Query = query
};
//var prefix = "java"; // NightOwl888: Prefix is no longer a feature
//Console.WriteLine(string.Format("prefix:{0}", prefix));
//Console.WriteLine("=============================");
var faceHandlers = new IFacetHandler[] { new SimpleFacetHandler("name") };
var browser = new BoboBrowser(BoboIndexReader.GetInstance(IndexReader.Open(_indexDir, true), faceHandlers));
var factSpec = new FacetSpec() { OrderBy = FacetSpec.FacetSortSpec.OrderHitsDesc };
request.SetFacetSpec("name", factSpec);
var result = browser.Browse(request);
foreach (var facet in result.FacetMap["name"].GetFacets())
{
Console.WriteLine(facet.ToString());
}
}