本文整理汇总了C#中Lucene.Net.Search.Sort类的典型用法代码示例。如果您正苦于以下问题:C# Sort类的具体用法?C# Sort怎么用?C# Sort使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Sort类属于Lucene.Net.Search命名空间,在下文中一共展示了Sort类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: TestString
public virtual void TestString()
{
Directory dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir);
Document doc = new Document();
doc.Add(NewStringField("value", "foo", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(NewStringField("value", "bar", Field.Store.YES));
writer.AddDocument(doc);
IndexReader ir = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
Sort sort = new Sort(new SortField("value", SortField.Type_e.STRING));
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
Assert.AreEqual(2, td.TotalHits);
// 'bar' comes before 'foo'
Assert.AreEqual("bar", searcher.Doc(td.ScoreDocs[0].Doc).Get("value"));
Assert.AreEqual("foo", searcher.Doc(td.ScoreDocs[1].Doc).Get("value"));
ir.Dispose();
dir.Dispose();
}
示例2: BuildQuery
/// <summary>
/// 构建Query、Filter、Sort
/// </summary>
/// <param name="query"><see cref="Query"/></param>
/// <param name="filter"><see cref="Filter"/></param>
/// <param name="sort"><see cref="Sort"/></param>
public void BuildQuery(out Query query, out Filter filter, out Sort sort)
{
BooleanQuery q = new BooleanQuery();
foreach (var clause in clauses)
{
q.Add(clause);
}
query = q;
if (filters.Count > 0)
{
BooleanQuery filterQuery = new BooleanQuery();
foreach (var _filter in filters)
filterQuery.Add(_filter);
filter = new QueryWrapperFilter(filterQuery);
}
else
{
filter = null;
}
if (sortFields.Count > 0)
sort = new Sort(sortFields.ToArray());
else
sort = null;
}
示例3: TestReverse
public void TestReverse()
{
Directory dir = NewDirectory();
RandomIndexWriter writer = new RandomIndexWriter(Random(), dir, Similarity, TimeZone);
Document doc = new Document();
doc.Add(NewStringField("value", "foo", Field.Store.NO));
doc.Add(NewStringField("value", "bar", Field.Store.NO));
doc.Add(NewStringField("id", "1", Field.Store.YES));
writer.AddDocument(doc);
doc = new Document();
doc.Add(NewStringField("value", "baz", Field.Store.NO));
doc.Add(NewStringField("id", "2", Field.Store.YES));
writer.AddDocument(doc);
IndexReader ir = writer.Reader;
writer.Dispose();
IndexSearcher searcher = NewSearcher(ir);
Sort sort = new Sort(new SortedSetSortField("value", true));
TopDocs td = searcher.Search(new MatchAllDocsQuery(), 10, sort);
assertEquals(2, td.TotalHits);
// 'bar' comes before 'baz'
assertEquals("2", searcher.Doc(td.ScoreDocs[0].Doc).Get("id"));
assertEquals("1", searcher.Doc(td.ScoreDocs[1].Doc).Get("id"));
ir.Dispose();
dir.Dispose();
}
示例4: TestReverseDateSort
public virtual void TestReverseDateSort()
{
IndexSearcher searcher = new IndexSearcher(directory);
// Create a Sort object. reverse is set to true.
// problem occurs only with SortField.AUTO:
Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.AUTO, true));
QueryParser queryParser = new QueryParser(TEXT_FIELD, new WhitespaceAnalyzer());
Query query = queryParser.Parse("Document");
// Execute the search and process the search results.
System.String[] actualOrder = new System.String[5];
ScoreDoc[] hits = searcher.Search(query, null, 1000, sort).scoreDocs;
for (int i = 0; i < hits.Length; i++)
{
Document document = searcher.Doc(hits[i].doc);
System.String text = document.Get(TEXT_FIELD);
actualOrder[i] = text;
}
searcher.Close();
// Set up the expected order (i.e. Document 5, 4, 3, 2, 1).
System.String[] expectedOrder = new System.String[5];
expectedOrder[0] = "Document 5";
expectedOrder[1] = "Document 4";
expectedOrder[2] = "Document 3";
expectedOrder[3] = "Document 2";
expectedOrder[4] = "Document 1";
Assert.AreEqual(new System.Collections.ArrayList(expectedOrder), new System.Collections.ArrayList(actualOrder));
}
示例5: TestOutOfOrderDocsScoringSort
public virtual void TestOutOfOrderDocsScoringSort()
{
// Two Sort criteria to instantiate the multi/single comparators.
Sort[] sort = new Sort[] { new Sort(SortField.FIELD_DOC), new Sort() };
bool[][] tfcOptions = new bool[][] { new bool[] { false, false, false }, new bool[] { false, false, true }, new bool[] { false, true, false }, new bool[] { false, true, true }, new bool[] { true, false, false }, new bool[] { true, false, true }, new bool[] { true, true, false }, new bool[] { true, true, true } };
string[] actualTFCClasses = new string[] { "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorNonScoringCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector", "OutOfOrderOneComparatorScoringNoMaxScoreCollector", "OutOfOrderOneComparatorScoringMaxScoreCollector" };
BooleanQuery bq = new BooleanQuery();
// Add a Query with SHOULD, since bw.Scorer() returns BooleanScorer2
// which delegates to BS if there are no mandatory clauses.
bq.Add(new MatchAllDocsQuery(), Occur.SHOULD);
// Set minNrShouldMatch to 1 so that BQ will not optimize rewrite to return
// the clause instead of BQ.
bq.MinimumNumberShouldMatch = 1;
for (int i = 0; i < sort.Length; i++)
{
for (int j = 0; j < tfcOptions.Length; j++)
{
TopDocsCollector<Entry> tdc = TopFieldCollector.Create(sort[i], 10, tfcOptions[j][0], tfcOptions[j][1], tfcOptions[j][2], false);
Assert.IsTrue(tdc.GetType().Name.EndsWith(actualTFCClasses[j]));
@is.Search(bq, tdc);
TopDocs td = tdc.TopDocs();
ScoreDoc[] sd = td.ScoreDocs;
Assert.AreEqual(10, sd.Length);
}
}
}
示例6: Search
public SearchResult Search(Query searchQuery, int maxHits, string NameField = "Name", Sort sort = null)
{
SearchResult result = new SearchResult();
TopDocs hits = null;
result.SearchResultItems = new List<SearchResultItem>();
if(sort != null)
{
hits = seacher.Search(searchQuery, null, maxHits, sort);
}
else
{
hits = seacher.Search(searchQuery, null, maxHits);
}
for (int i = 0; i < hits.ScoreDocs.Count(); i++)
{
Document doctemp = seacher.Doc(hits.ScoreDocs[i].Doc);
result.SearchResultItems.Add(new SearchResultItem
{
Id = int.Parse(doctemp.Get("Id")),
Name = doctemp.Get(NameField),
Type = (DocumentType) Enum.Parse(typeof(DocumentType), doctemp.Get("Type"))
});
}
result.Hits = hits.ScoreDocs.Count();
return result;
}
示例7: TestReverseDateSort
public virtual void TestReverseDateSort()
{
IndexSearcher searcher = NewSearcher(Reader);
Sort sort = new Sort(new SortField(DATE_TIME_FIELD, SortField.Type_e.STRING, true));
Query query = new TermQuery(new Term(TEXT_FIELD, "document"));
// Execute the search and process the search results.
string[] actualOrder = new string[5];
ScoreDoc[] hits = searcher.Search(query, null, 1000, sort).ScoreDocs;
for (int i = 0; i < hits.Length; i++)
{
Document document = searcher.Doc(hits[i].Doc);
string text = document.Get(TEXT_FIELD);
actualOrder[i] = text;
}
// Set up the expected order (i.e. Document 5, 4, 3, 2, 1).
string[] expectedOrder = new string[5];
expectedOrder[0] = "Document 5";
expectedOrder[1] = "Document 4";
expectedOrder[2] = "Document 3";
expectedOrder[3] = "Document 2";
expectedOrder[4] = "Document 1";
Assert.AreEqual(Arrays.AsList(expectedOrder), Arrays.AsList(actualOrder));
}
示例8: Search
public SearchHits Search(PreparedQuery query, Sort sort, int maxResults = DefaultMaximumResults)
{
#if FEATURE_CONTENT_SEARCH
return new SearchHits(Searcher.Search(query.Query, null, maxResults, sort), Searcher.IndexReader);
#else
return new SearchHits(Searcher.Search(query.Query, sort));
#endif
}
示例9: BuildSort
public virtual void BuildSort()
{
if (SortFields.Count == 0)
{
return;
}
CurrentSort = new Sort(SortFields.ToArray());
}
示例10: Search
public SearchHits Search(PreparedQuery query, Sort sort, int maxResults = DefaultMaximumResults)
{
#if SC62 || SC64 || SC66
return new SearchHits(Searcher.Search(query.Query, sort));
#else
return new SearchHits(Searcher.Search(query.Query, null, maxResults, sort), Searcher.IndexReader);
#endif
}
示例11: Hits
internal Hits(Searcher s, Query q, Filter f, Sort o)
{
weight = q.Weight(s);
searcher = s;
filter = f;
sort = o;
GetMoreDocs(50); // retrieve 100 initially
}
示例12: Search
public SearchHits Search(Query query, Sort sort)
{
//Fix for #384289. Previous code line returned PreparedQuery. PreparedQuery made FullText queries from all queries,
//for example _name:test query became _name:test*. It produced wrong search results, so I decided to remove
//PreparedQuery part. If something wrong noticed during usage, PreparedQuery should be return
//and other logic should be created for this part.
//return Search(query, SearchContext.Empty, sort); - this returned PreparedQuery.
return new SearchHits(Searcher.Search(query, sort));
}
示例13: DisplayResults
public void DisplayResults(Query query, Sort sort)
{
using(var indexSearcher = new IndexSearcher(directory, true))
{
indexSearcher.SetDefaultFieldSortScoring(true, false);
var results = indexSearcher.Search(query, null, 20, sort);
Console.WriteLine("\nResults for: {0} sorted by {1}", query, sort);
Console.WriteLine();
}
}
示例14: Hits
internal Hits(Searcher s, Query q, Filter f, Sort o)
{
weight = q.Weight(s);
searcher = s;
filter = f;
sort = o;
nDeletions = CountDeletions(s);
GetMoreDocs(50); // retrieve 100 initially
lengthAtStart = length;
}
示例15: PreviousSearchState
public PreviousSearchState(Query query, Sort sort, ScoreDoc searchAfterLocal, ScoreDoc searchAfterShard, long[] versions, int numHitsPaged)
{
this.Versions = (long[])versions.Clone();
this.SearchAfterLocal = searchAfterLocal;
this.SearchAfterShard = searchAfterShard;
this.Sort = sort;
this.Query = query;
this.NumHitsPaged = numHitsPaged;
SearchTimeNanos = TimeHelper.NanoTime();
}