本文整理汇总了C#中Lucene.Net.Search.TopDocs类的典型用法代码示例。如果您正苦于以下问题:C# TopDocs类的具体用法?C# TopDocs怎么用?C# TopDocs使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TopDocs类属于Lucene.Net.Search命名空间,在下文中一共展示了TopDocs类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Medidas
public Medidas(TopDocs hits, Searcher searcher, List<int> docs)
{
this.qtdDocsRelevantesRetornados = DocsRelevantesRecuperados(hits, searcher, docs);
this.precisao = _Precisao(hits.ScoreDocs.Length);
this.cobetura = _Cobertura(docs.Count);
this.fmeasure = _FMeasure();
}
示例2: LuceneSearchResults
/// <summary>
/// Initializes a new instance of the <see cref="SearchResults" /> class.
/// </summary>
/// <param name="searcher">The searcher.</param>
/// <param name="reader">The reader.</param>
/// <param name="docs">The hits.</param>
/// <param name="criteria">The criteria.</param>
/// <param name="query">The query.</param>
public LuceneSearchResults(Searcher searcher, IndexReader reader, TopDocs docs, ISearchCriteria criteria, Query query)
{
Results = new SearchResults(criteria, null);
CreateDocuments(searcher, docs);
CreateFacets(reader, query);
CreateSuggestions(reader, criteria);
}
示例3: GetResults
private static void GetResults(ref List<Airport> itemsList, TopDocs results, Searcher searcher)
{
foreach (ScoreDoc scoreDoc in results.ScoreDocs)
{
var item = new Airport();
Document doc = searcher.Doc(scoreDoc.Doc);
item.id = doc.Get("Code");
item.label = doc.Get("CityName") + " - " + doc.Get("Name") + " (" +
doc.Get("Code") + ")";
item.value = doc.Get("CityName") + " - " + doc.Get("Name") + " (" +
doc.Get("Code") + ")";
itemsList.Add(item);
}
}
示例4: HitsIncludeTitle
public static bool HitsIncludeTitle(IndexSearcher searcher, TopDocs topDocs, String title)
{
foreach (var scoreDoc in topDocs.ScoreDocs)
{
var doc = searcher.Doc(scoreDoc.Doc);
var docTitle = doc.Get("title");
var decodedTitle = DecodeEncodedNonAsciiCharacters(docTitle);
if (decodedTitle.Equals(title))
{
return true;
}
}
Console.WriteLine("title '" + title + "' not found");
return false;
}
示例5: CreateDocuments
/// <summary>
/// Creates result document collection from Lucene documents.
/// </summary>
/// <param name="searcher">The searcher.</param>
/// <param name="topDocs">The hits.</param>
private void CreateDocuments(Searcher searcher, TopDocs topDocs)
{
// if no documents found return
if (topDocs == null)
return;
var entries = new List<ResultDocument>();
// get total hits
var totalCount = topDocs.TotalHits;
var recordsToRetrieve = Results.SearchCriteria.RecordsToRetrieve;
var startIndex = Results.SearchCriteria.StartingRecord;
if (recordsToRetrieve > totalCount)
recordsToRetrieve = totalCount;
for (var index = startIndex; index < startIndex + recordsToRetrieve; index++)
{
if (index >= totalCount)
break;
var document = searcher.Doc(topDocs.ScoreDocs[index].Doc);
var doc = new ResultDocument();
var documentFields = document.GetFields();
using (var fi = documentFields.GetEnumerator())
{
while (fi.MoveNext())
{
if (fi.Current != null)
{
var field = fi.Current;
doc.Add(new DocumentField(field.Name, field.StringValue));
}
}
}
entries.Add(doc);
}
var searchDocuments = new ResultDocumentSet
{
Name = "Items",
Documents = entries.OfType<IDocument>().ToArray(),
TotalCount = totalCount
};
Results.Documents = new[] { searchDocuments };
}
示例6: DocsRelevantesRecuperados
private int DocsRelevantesRecuperados(TopDocs hits, Searcher searcher, List<int> docs)
{
int qtd = 0;
foreach (ScoreDoc scoreDoc in hits.ScoreDocs)
{
Document doc = searcher.GetDocument(scoreDoc);
string docId = doc.Get(Constants.FILE_NAME);
string number = docId.Substring(docId.IndexOf('(')+1, docId.IndexOf(')') - docId.IndexOf('(') - 1);
int num = Int32.Parse(number);
if (docs.Contains(num))
qtd++;
}
return qtd;
}
示例7: WriteV2ResultTest
public void WriteV2ResultTest(
string indexName,
int numDocs,
Dictionary<string, string> commitUserData,
int topDocsTotalHits,
float topDocsMaxScore,
int skip,
int take,
string expected)
{
var searcher = new MockSearcher(indexName, numDocs, commitUserData, versions: Constants.VersionResults);
var topDocs = new TopDocs(topDocsTotalHits, Constants.ScoreDocs, topDocsMaxScore);
var sb = new StringBuilder();
var sw = new StringWriter(sb);
using (var writer = new JsonTextWriter(sw))
{
ResponseFormatter.WriteV2Result(writer, searcher, topDocs, skip, take);
Assert.Equal(expected, sb.ToString());
}
}
示例8: Search
/// <summary> A search implementation which executes each
/// <see cref="Searchable"/> in its own thread and waits for each search to complete
/// and merge the results back together.
/// </summary>
public override TopDocs Search(Weight weight, Filter filter, int nDocs)
{
HitQueue hq = new HitQueue(nDocs, false);
object lockObj = new object();
TopDocs[] results = new TopDocs[searchables.Length];
//search each searchable
Parallel.For(0, searchables.Length, (i) => results[i] = MultiSearcherCallableNoSort(ThreadLock.MonitorLock, lockObj, searchables[i], weight, filter,
nDocs, hq, i, starts));
int totalHits = 0;
float maxScore = float.NegativeInfinity;
foreach (TopDocs topDocs in results)
{
totalHits += topDocs.TotalHits;
maxScore = Math.Max(maxScore, topDocs.MaxScore);
}
ScoreDoc[] scoreDocs = new ScoreDoc[hq.Size()];
for (int i = hq.Size() - 1; i >= 0; i--) // put docs in array
scoreDocs[i] = hq.Pop();
return new TopDocs(totalHits, scoreDocs, maxScore);
}
示例9: CompareHits
private void CompareHits(IndexReader r, IndexReader joinR, TopDocs results, TopGroups<int> joinResults)
{
// results is 'complete'; joinResults is a subset
int resultUpto = 0;
int joinGroupUpto = 0;
ScoreDoc[] hits = results.ScoreDocs;
IGroupDocs<int>[] groupDocs = joinResults.Groups;
while (joinGroupUpto < groupDocs.Length)
{
IGroupDocs<int> group = groupDocs[joinGroupUpto++];
ScoreDoc[] groupHits = group.ScoreDocs;
assertNotNull(group.GroupValue);
Document parentDoc = joinR.Document(group.GroupValue);
string parentID = parentDoc.Get("parentID");
//System.out.println("GROUP groupDoc=" + group.groupDoc + " parent=" + parentDoc);
assertNotNull(parentID);
assertTrue(groupHits.Length > 0);
for (int hitIDX = 0; hitIDX < groupHits.Length; hitIDX++)
{
Document nonJoinHit = r.Document(hits[resultUpto++].Doc);
Document joinHit = joinR.Document(groupHits[hitIDX].Doc);
assertEquals(parentID, nonJoinHit.Get("parentID"));
assertEquals(joinHit.Get("childID"), nonJoinHit.Get("childID"));
}
if (joinGroupUpto < groupDocs.Length)
{
// Advance non-join hit to the next parentID:
//System.out.println(" next joingroupUpto=" + joinGroupUpto + " gd.Length=" + groupDocs.Length + " parentID=" + parentID);
while (true)
{
assertTrue(resultUpto < hits.Length);
if (!parentID.Equals(r.Document(hits[resultUpto].Doc).Get("parentID")))
{
break;
}
resultUpto++;
}
}
}
}
示例10: getResults
private IEnumerable<IAuditEntry> getResults(TopDocs ids, int page, IndexSearcher searcher)
{
int skip = page*20;
return ids.ScoreDocs.Reverse().Skip(skip).Take(20).Select(x => new BasicAuditEntry(searcher.Doc(x.Doc), x.Doc));
}
示例11: TopDocsToMap
// since custom scoring modifies the order of docs, map results
// by doc ids so that we can later compare/verify them
private System.Collections.Hashtable TopDocsToMap(TopDocs td)
{
System.Collections.Hashtable h = new System.Collections.Hashtable();
for (int i = 0; i < td.TotalHits; i++)
{
h[(System.Int32) td.ScoreDocs[i].Doc] = (float) td.ScoreDocs[i].Score;
}
return h;
}
示例12: CompareChildHits
private void CompareChildHits(IndexReader r, IndexReader joinR, TopDocs results, TopDocs joinResults)
{
assertEquals(results.TotalHits, joinResults.TotalHits);
assertEquals(results.ScoreDocs.Length, joinResults.ScoreDocs.Length);
for (int hitCount = 0; hitCount < results.ScoreDocs.Length; hitCount++)
{
ScoreDoc hit = results.ScoreDocs[hitCount];
ScoreDoc joinHit = joinResults.ScoreDocs[hitCount];
Document doc1 = r.Document(hit.Doc);
Document doc2 = joinR.Document(joinHit.Doc);
assertEquals("hit " + hitCount + " differs", doc1.Get("childID"), doc2.Get("childID"));
// don't compare scores -- they are expected to differ
assertTrue(hit is FieldDoc);
assertTrue(joinHit is FieldDoc);
FieldDoc hit0 = (FieldDoc)hit;
FieldDoc joinHit0 = (FieldDoc)joinHit;
assertArrayEquals(hit0.Fields, joinHit0.Fields);
}
}
示例13: AutoCompleteMakeResult
public static JToken AutoCompleteMakeResult(IndexSearcher searcher, TopDocs topDocs, int skip, int take, NuGetSearcherManager searcherManager, bool includeExplanation, Query query)
{
JArray array = new JArray();
for (int i = skip; i < Math.Min(skip + take, topDocs.ScoreDocs.Length); i++)
{
ScoreDoc scoreDoc = topDocs.ScoreDocs[i];
Document document = searcher.Doc(scoreDoc.Doc);
string id = document.Get("Id");
array.Add(id);
}
JObject result = new JObject();
result.Add("@context", new JObject { { "@vocab", "http://schema.nuget.org/schema#" } });
result.Add("totalHits", topDocs.TotalHits);
result.Add("indexName", searcherManager.IndexName);
result.Add("data", array);
if (includeExplanation)
{
JArray explanations = new JArray();
for (int i = skip; i < Math.Min(skip + take, topDocs.ScoreDocs.Length); i++)
{
ScoreDoc scoreDoc = topDocs.ScoreDocs[i];
Explanation explanation = searcher.Explain(query, scoreDoc.Doc);
explanations.Add(explanation.ToString());
}
result.Add("explanations", explanations);
}
return result;
}
示例14: GetTopDocuments
public List<Document> GetTopDocuments(TopDocs topDocs)
{
return topDocs == null ? null : (from ScoreDoc doc in topDocs.ScoreDocs select GetDocument(doc.doc)).ToList();
}
示例15: SearchAfter
public override TopDocs SearchAfter(ScoreDoc after, Query query, int numHits)
{
TopDocs[] shardHits = new TopDocs[NodeVersions.Length];
// results are merged in that order: score, shardIndex, doc. therefore we set
// after to after.Score and depending on the nodeID we set doc to either:
// - not collect any more documents with that score (only with worse score)
// - collect more documents with that score (and worse) following the last collected document
// - collect all documents with that score (and worse)
ScoreDoc shardAfter = new ScoreDoc(after.Doc, after.Score);
for (int nodeID = 0; nodeID < NodeVersions.Length; nodeID++)
{
if (nodeID < after.ShardIndex)
{
// all documents with after.Score were already collected, so collect
// only documents with worse scores.
NodeState.ShardIndexSearcher s = OuterInstance.OuterInstance.Nodes[nodeID].Acquire(NodeVersions);
try
{
// Setting after.Doc to reader.MaxDoc-1 is a way to tell
// TopScoreDocCollector that no more docs with that score should
// be collected. note that in practice the shard which sends the
// request to a remote shard won't have reader.MaxDoc at hand, so
// it will send some arbitrary value which will be fixed on the
// other end.
shardAfter.Doc = s.IndexReader.MaxDoc - 1;
}
finally
{
OuterInstance.OuterInstance.Nodes[nodeID].Release(s);
}
}
else if (nodeID == after.ShardIndex)
{
// collect all documents following the last collected doc with
// after.Score + documents with worse scores.
shardAfter.Doc = after.Doc;
}
else
{
// all documents with after.Score (and worse) should be collected
// because they didn't make it to top-N in the previous round.
shardAfter.Doc = -1;
}
if (nodeID == MyNodeID)
{
// My node; run using local shard searcher we
// already aquired:
shardHits[nodeID] = LocalSearchAfter(shardAfter, query, numHits);
}
else
{
shardHits[nodeID] = OuterInstance.OuterInstance.SearchNode(nodeID, NodeVersions, query, null, numHits, shardAfter);
}
//System.out.println(" node=" + nodeID + " totHits=" + shardHits[nodeID].TotalHits);
}
// Merge:
return TopDocs.Merge(null, numHits, shardHits);
}