本文整理汇总了C#中Lucene.Net.Search.Sort.SetSort方法的典型用法代码示例。如果您正苦于以下问题:C# Sort.SetSort方法的具体用法?C# Sort.SetSort怎么用?C# Sort.SetSort使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.Sort
的用法示例。
在下文中一共展示了Sort.SetSort方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetHitsByFiled
private Hits GetHitsByFiled(string filedname,Analyzer analyzer, string searchStr, IndexSearcher searcher)
{
MultiFieldQueryParser parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_CURRENT, new string[] { filedname}, analyzer);
Query query = parser.Parse(searchStr);
Sort sort = new Sort();
SortField f = new SortField("publish_time", SortField.STRING, true);//按照publish_time字段排序,true表示降序
sort.SetSort(f);
Hits hits = searcher.Search(query, sort);
return hits;
}
示例2: TestEmptyIndex
public virtual void TestEmptyIndex()
{
Searcher empty = EmptyIndex;
sort = new Sort();
AssertMatches(empty, queryX, sort, "");
sort.SetSort(SortField.FIELD_DOC);
AssertMatches(empty, queryX, sort, "");
sort.SetSort(new SortField[]{new SortField("int", SortField.INT), SortField.FIELD_DOC});
AssertMatches(empty, queryX, sort, "");
sort.SetSort(new SortField[]{new SortField("string", SortField.STRING, true), SortField.FIELD_DOC});
AssertMatches(empty, queryX, sort, "");
sort.SetSort(new SortField[]{new SortField("float", SortField.FLOAT), new SortField("string", SortField.STRING)});
AssertMatches(empty, queryX, sort, "");
}
示例3: TestNormalizedScores
public virtual void TestNormalizedScores()
{
// capture relevancy scores
System.Collections.Hashtable scoresX = GetScores(full.Search(queryX));
System.Collections.Hashtable scoresY = GetScores(full.Search(queryY));
System.Collections.Hashtable scoresA = GetScores(full.Search(queryA));
// we'll test searching locally, remote and multi
// note: the multi test depends on each separate index containing
// the same documents as our local index, so the computed normalization
// will be the same. so we make a multi searcher over two equal document
// sets - not realistic, but necessary for testing.
MultiSearcher remote = new MultiSearcher(new Lucene.Net.Search.Searchable[]{Remote});
MultiSearcher multi = new MultiSearcher(new Lucene.Net.Search.Searchable[]{full, full});
// change sorting and make sure relevancy stays the same
sort = new Sort();
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort(SortField.FIELD_DOC);
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort("int");
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort("float");
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort("string");
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort(new System.String[]{"int", "float"});
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort(new SortField[]{new SortField("int", true), new SortField(null, SortField.DOC, true)});
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(remote.Search(queryY, sort)));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, sort)));
AssertSameValues(scoresA, GetScores(full.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(remote.Search(queryA, sort)));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, sort)));
sort.SetSort(new System.String[]{"float", "string"});
AssertSameValues(scoresX, GetScores(full.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(remote.Search(queryX, sort)));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, sort)));
AssertSameValues(scoresY, GetScores(full.Search(queryY, sort)));
//.........这里部分代码省略.........
示例4: TestNormalizedScores
public virtual void TestNormalizedScores()
{
// capture relevancy scores
System.Collections.Hashtable scoresX = GetScores(full.Search(queryX, null, 1000).ScoreDocs, full);
System.Collections.Hashtable scoresY = GetScores(full.Search(queryY, null, 1000).ScoreDocs, full);
System.Collections.Hashtable scoresA = GetScores(full.Search(queryA, null, 1000).ScoreDocs, full);
// we'll test searching locally, remote and multi
MultiSearcher multi = new MultiSearcher(new Searchable[]{searchX, searchY});
// change sorting and make sure relevancy stays the same
sort = new Sort();
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort(SortField.FIELD_DOC);
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort("int");
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort("float");
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort("string");
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort(new System.String[]{"int", "float"});
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort(new SortField[]{new SortField("int", true), new SortField(null, SortField.DOC, true)});
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
sort.SetSort(new System.String[]{"float", "string"});
AssertSameValues(scoresX, GetScores(full.Search(queryX, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresX, GetScores(multi.Search(queryX, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresY, GetScores(full.Search(queryY, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresY, GetScores(multi.Search(queryY, null, 1000, sort).ScoreDocs, multi));
AssertSameValues(scoresA, GetScores(full.Search(queryA, null, 1000, sort).ScoreDocs, full));
AssertSameValues(scoresA, GetScores(multi.Search(queryA, null, 1000, sort).ScoreDocs, multi));
}
示例5: TestBuiltInSorts
public virtual void TestBuiltInSorts()
{
sort = new Sort();
AssertMatches(full, queryX, sort, "ACEGI");
AssertMatches(full, queryY, sort, "BDFHJ");
sort.SetSort(SortField.FIELD_DOC);
AssertMatches(full, queryX, sort, "ACEGI");
AssertMatches(full, queryY, sort, "BDFHJ");
}
示例6: TestSort
public virtual void TestSort()
{
this.r = NewRandom();
// reverse & not
// all types
// restrictive & non restrictive searches (on contents)
Create();
Sort[] sorts = new Sort[50];
int sortCount = 0;
for (int r = 0; r < 2; r++)
{
Sort sort;
bool reverse = 1 == r;
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("byte", SortField.BYTE, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("short", SortField.SHORT, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("int", SortField.INT, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("long", SortField.LONG, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("float", SortField.FLOAT, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("double", SortField.DOUBLE, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("string", SortField.STRING_VAL, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField("stringIdx", SortField.STRING, reverse)});
//sorts[sortCount++] = sort = new Sort();
//sort.setSort(new SortField[] {new SortField("string", SortField.STRING_ORD, reverse)});
//sorts[sortCount++] = sort = new Sort();
//sort.setSort(new SortField[] {new SortField("string", SortField.STRING_ORD_VAL, reverse)});
//sorts[sortCount++] = sort = new Sort();
//sort.setSort(new SortField[] {new SortField("string", SortField.STRING_ORD_VAL_DEM, reverse)});
//sorts[sortCount++] = sort = new Sort();
//sort.setSort(new SortField[] {new SortField("string", SortField.STRING_ORD_VAL_DEM2, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField(null, SortField.SCORE, reverse)});
sorts[sortCount++] = sort = new Sort();
sort.SetSort(new SortField[]{new SortField(null, SortField.DOC, reverse)});
}
Query[] queries = new Query[4];
queries[0] = new MatchAllDocsQuery();
queries[1] = new TermQuery(new Term("contents", "x")); // matches every 10th doc
queries[2] = new TermQuery(new Term("contents", "y")); // matches every 100th doc
queries[3] = new TermQuery(new Term("contents", "z")); // matches every 1000th doc
for (int sx = 0; sx < 3; sx++)
{
IndexSearcher searcher;
if (sx == 0)
{
searcher = searcherSingleSegment;
}
else if (sx == 1)
{
searcher = searcherFewSegment;
}
else
{
searcher = searcherMultiSegment;
}
for (int qx = 0; qx < queries.Length; qx++)
{
Query query = queries[qx];
for (int q = 0; q < 3; q++)
{
int queueSize;
if (q == 0)
{
queueSize = 10;
}
else if (q == 1)
{
queueSize = 100;
}
else
//.........这里部分代码省略.........
示例7: TestEmptyIndex
public virtual void TestEmptyIndex()
{
IndexSearcher empty = NewSearcher(new MultiReader());
Query query = new TermQuery(new Term("contents", "foo"));
Sort sort = new Sort();
TopDocs td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
sort.SetSort(SortField.FIELD_DOC);
td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
sort.SetSort(new SortField("int", SortField.Type_e.INT), SortField.FIELD_DOC);
td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
sort.SetSort(new SortField("string", SortField.Type_e.STRING, true), SortField.FIELD_DOC);
td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
sort.SetSort(new SortField("string_val", SortField.Type_e.STRING_VAL, true), SortField.FIELD_DOC);
td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
sort.SetSort(new SortField("float", SortField.Type_e.FLOAT), new SortField("string", SortField.Type_e.STRING));
td = empty.Search(query, null, 10, sort, true, true);
Assert.AreEqual(0, td.TotalHits);
}
示例8: TestEmptyIndex
public void TestEmptyIndex()
{
IndexSearcher empty = NewSearcher(new MultiReader());
Query query = new TermQuery(new Term("contents", "foo"));
Sort sort = new Sort();
sort.SetSort(new SortedSetSortField("sortedset", false));
TopDocs td = empty.Search(query, null, 10, sort, true, true);
assertEquals(0, td.TotalHits);
// for an empty index, any selector should work
foreach (Selector v in Enum.GetValues(typeof(Selector)))
{
sort.SetSort(new SortedSetSortField("sortedset", false, v));
td = empty.Search(query, null, 10, sort, true, true);
assertEquals(0, td.TotalHits);
}
}
示例9: LUCENENET_100_ClientSearch
void LUCENENET_100_ClientSearch()
{
try
{
Lucene.Net.Search.Searchable s = (Lucene.Net.Search.Searchable)Activator.GetObject(typeof(Lucene.Net.Search.Searchable), @"tcp://localhost:" + ANYPORT + "/Searcher");
Lucene.Net.Search.MultiSearcher searcher = new Lucene.Net.Search.MultiSearcher(new Lucene.Net.Search.Searchable[] { s });
Lucene.Net.Search.Query q = new Lucene.Net.Search.TermQuery(new Lucene.Net.Index.Term("field1", "moon"));
Lucene.Net.Search.Sort sort = new Lucene.Net.Search.Sort();
sort.SetSort(new Lucene.Net.Search.SortField("field2", Lucene.Net.Search.SortField.INT));
Lucene.Net.Search.TopDocs h = searcher.Search(q, null,100, sort);
if (h.ScoreDocs.Length != 2) LUCENENET_100_Exception = new Exception("Test_Search_FieldDoc Error. ");
}
catch (Exception ex)
{
LUCENENET_100_Exception = ex;
}
finally
{
LUCENENET_100_testFinished = true;
}
}
示例10: TestIndexAndSearch
void TestIndexAndSearch(string tempDir)
{
Lucene.Net.Store.Directory dir = Lucene.Net.Store.FSDirectory.Open(new System.IO.DirectoryInfo(tempDir));
Lucene.Net.Index.IndexWriter w = new Lucene.Net.Index.IndexWriter(dir, new Lucene.Net.Analysis.Standard.StandardAnalyzer(), true);
Lucene.Net.Documents.Field f1 = new Lucene.Net.Documents.Field("field1", "dark side of the moon", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED);
Lucene.Net.Documents.Field f2 = new Lucene.Net.Documents.Field("field2", "123", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED);
Lucene.Net.Documents.Document d = new Lucene.Net.Documents.Document();
d.Add(f1);
d.Add(f2);
w.AddDocument(d);
f1 = new Lucene.Net.Documents.Field("field1", "Fly me to the moon", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.TOKENIZED);
f2 = new Lucene.Net.Documents.Field("field2", "456", Lucene.Net.Documents.Field.Store.YES, Lucene.Net.Documents.Field.Index.UN_TOKENIZED);
d = new Lucene.Net.Documents.Document();
d.Add(f1);
d.Add(f2);
w.AddDocument(d);
w.Close();
Lucene.Net.Search.IndexSearcher searcher = new IndexSearcher(dir, true);
Lucene.Net.Search.Sort sort = new Lucene.Net.Search.Sort();
sort.SetSort(new Lucene.Net.Search.SortField("field2", Lucene.Net.Search.SortField.STRING));
Lucene.Net.Search.Query q = new Lucene.Net.QueryParsers.QueryParser("field1", new Lucene.Net.Analysis.Standard.StandardAnalyzer()).Parse("moon");
TopDocs td = searcher.Search(q, null, 100, sort);
int resCount = td.ScoreDocs.Length;
searcher.Close();
}