本文整理汇总了C#中Lucene.Net.Search.Searcher.Doc方法的典型用法代码示例。如果您正苦于以下问题:C# Searcher.Doc方法的具体用法?C# Searcher.Doc怎么用?C# Searcher.Doc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.Searcher
的用法示例。
在下文中一共展示了Searcher.Doc方法的12个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
}
示例2: 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 };
}
示例3: PrintHits
protected internal virtual void PrintHits(System.String test, ScoreDoc[] h, Searcher searcher)
{
System.Console.Error.WriteLine("------- " + test + " -------");
for (int i = 0; i < h.Length; i++)
{
Document d = searcher.Doc(h[i].Doc);
float score = h[i].Score;
System.Console.Error.WriteLine("#" + i + ": {0.000000}" + score + " - " + d.Get("id") + " - " + d.Get("data"));
}
}
示例4: assertHits
/// <summary> Checks to see if the hits are what we expected.
///
/// </summary>
/// <param name="query">the query to execute
/// </param>
/// <param name="description">the description of the search
/// </param>
/// <param name="expectedIds">the expected document ids of the hits
/// </param>
/// <param name="expectedScores">the expected scores of the hits
///
/// </param>
/// <throws> IOException </throws>
protected internal static void assertHits(Searcher s, Query query, System.String description, System.String[] expectedIds, float[] expectedScores)
{
QueryUtils.Check(query, s);
float tolerance = 1e-5f;
// Hits hits = searcher.search(query);
// hits normalizes and throws things off if one score is greater than 1.0
TopDocs topdocs = s.Search(query, null, 10000);
/***
// display the hits
System.out.println(hits.length() + " hits for search: \"" + description + '\"');
for (int i = 0; i < hits.length(); i++) {
System.out.println(" " + FIELD_ID + ':' + hits.doc(i).get(FIELD_ID) + " (score:" + hits.score(i) + ')');
}
*****/
// did we get the hits we expected
Assert.AreEqual(expectedIds.Length, topdocs.TotalHits);
for (int i = 0; i < topdocs.TotalHits; i++)
{
//System.out.println(i + " exp: " + expectedIds[i]);
//System.out.println(i + " field: " + hits.doc(i).get(FIELD_ID));
int id = topdocs.ScoreDocs[i].Doc;
float score = topdocs.ScoreDocs[i].Score;
Document doc = s.Doc(id);
Assert.AreEqual(expectedIds[i], doc.Get(FIELD_ID));
bool scoreEq = System.Math.Abs(expectedScores[i] - score) < tolerance;
if (!scoreEq)
{
System.Console.Out.WriteLine(i + " warning, expected score: " + expectedScores[i] + ", actual " + score);
System.Console.Out.WriteLine(s.Explain(query, id));
}
Assert.AreEqual(expectedScores[i], score, tolerance);
Assert.AreEqual(s.Explain(query, id).Value, score, tolerance);
}
}
示例5: GetScores
private System.Collections.Hashtable GetScores(ScoreDoc[] hits, Searcher searcher)
{
System.Collections.Hashtable scoreMap = new System.Collections.Hashtable();
int n = hits.Length;
for (int i = 0; i < n; ++i)
{
Document doc = searcher.Doc(hits[i].Doc);
System.String[] v = doc.GetValues("tracer");
Assert.AreEqual(v.Length, 1);
scoreMap[v[0]] = (float) hits[i].Score;
}
return scoreMap;
}
示例6: AssertMatches
// make sure the documents returned by the search match the expected list
private void AssertMatches(Searcher searcher, Query query, Sort sort, System.String expectedResult)
{
//ScoreDoc[] result = searcher.search (query, null, 1000, sort).scoreDocs;
TopDocs hits = searcher.Search(query, null, expectedResult.Length, sort);
ScoreDoc[] result = hits.ScoreDocs;
Assert.AreEqual(hits.TotalHits, expectedResult.Length);
System.Text.StringBuilder buff = new System.Text.StringBuilder(10);
int n = result.Length;
for (int i = 0; i < n; ++i)
{
Document doc = searcher.Doc(result[i].Doc);
System.String[] v = doc.GetValues("tracer");
for (int j = 0; j < v.Length; ++j)
{
buff.Append(v[j]);
}
}
Assert.AreEqual(expectedResult, buff.ToString());
}
示例7: CheckHits
private void CheckHits(ScoreDoc[] hits, int expectedCount, Searcher searcher)
{
Assert.AreEqual(expectedCount, hits.Length, "total results");
for (int i = 0; i < hits.Length; i++)
{
if (i < 10 || (i > 94 && i < 105))
{
Document d = searcher.Doc(hits[i].Doc);
Assert.AreEqual(System.Convert.ToString(i), d.Get(ID_FIELD), "check " + i);
}
}
}
示例8: PrintHits
private void PrintHits(System.IO.StreamWriter out_Renamed, ScoreDoc[] hits, Searcher searcher)
{
out_Renamed.WriteLine(hits.Length + " total results\n");
for (int i = 0; i < hits.Length; i++)
{
if (i < 10 || (i > 94 && i < 105))
{
Document d = searcher.Doc(hits[i].Doc);
out_Renamed.WriteLine(i + " " + d.Get(ID_FIELD));
}
}
}
示例9: GetResultPage
protected IEnumerable<LucObject> GetResultPage(ScoreDoc[] hits, Searcher searcher, int howMany, bool allVersions, out bool noMoreHits)
{
var result = new List<LucObject>();
noMoreHits = false;
if (hits.Length == 0)
return result;
var user = this.LucQuery.User;
var currentUser = AccessProvider.Current.GetCurrentUser();
if (user == null)
user = currentUser;
var isCurrentUser = user.Id == currentUser.Id;
var upperBound = hits.Length;
var index = 0;
while (true)
{
Document doc = searcher.Doc(hits[index].Doc);
if (allVersions || IsPermitted(doc, user, isCurrentUser))
{
result.Add(new LucObject(doc));
if (result.Count == howMany)
{
noMoreHits = false;
break;
}
}
if (++index >= upperBound)
{
noMoreHits = true;
break;
}
}
return result;
//foreach (var hit in hits)
//{
// Document doc = searcher.Doc(hit.doc);
// if (allVersions || IsPermitted(doc, user, isCurrentUser))
// {
// result.Add(new LucObject(doc));
// if (result.Count == howMany)
// break;
// }
//}
//return result;
/*
Logger.Write(this.LucQuery.QueryText);
//var startIndex = this.StartIndex;
var pageSize = this.LucQuery.PageSize;
if (pageSize == 0)
pageSize = Int32.MaxValue;
var top = this.LucQuery.Top;
if (top == 0)
top = Int32.MaxValue;
if (top < pageSize)
pageSize = top;
var countInPage = 0;
var result = new List<LucObject>();
var user = this.LucQuery.User;
var currentUser = AccessProvider.Current.GetCurrentUser();
if (user == null)
user = currentUser;
var isCurrentUser = user.Id == currentUser.Id;
foreach (var hit in hits)
{
Document doc = searcher.Doc(hit.doc);
if (allVersions || IsPermitted(doc, user, isCurrentUser))
{
if (countInPage++ >= pageSize)
break;
result.Add(new LucObject(doc));
}
}
return result;
*/
}
示例10: DoPagingSearch
/// <summary> This demonstrates a typical paging search scenario, where the search engine presents
/// pages of size n to the user. The user can then go to the next page if interested in
/// the next hits.
///
/// When the query is executed for the first time, then only enough results are collected
/// to fill 5 result pages. If the user wants to page beyond this limit, then the query
/// is executed another time and all hits are collected.
///
/// </summary>
public static void DoPagingSearch(StreamReader input, Searcher searcher, Query query, int hitsPerPage, bool raw, bool interactive)
{
// Collect enough docs to show 5 pages
var collector = TopScoreDocCollector.Create(5 * hitsPerPage, false);
searcher.Search(query, collector);
var hits = collector.TopDocs().ScoreDocs;
int numTotalHits = collector.TotalHits;
Console.Out.WriteLine(numTotalHits + " total matching documents");
int start = 0;
int end = Math.Min(numTotalHits, hitsPerPage);
while (true)
{
if (end > hits.Length)
{
Console.Out.WriteLine("Only results 1 - " + hits.Length + " of " + numTotalHits + " total matching documents collected.");
Console.Out.WriteLine("Collect more (y/n) ?");
String line = input.ReadLine();
if (String.IsNullOrEmpty(line) || line[0] == 'n')
{
break;
}
collector = TopScoreDocCollector.Create(numTotalHits, false);
searcher.Search(query, collector);
hits = collector.TopDocs().ScoreDocs;
}
end = Math.Min(hits.Length, start + hitsPerPage);
for (int i = start; i < end; i++)
{
if (raw)
{
// output raw format
Console.Out.WriteLine("doc=" + hits[i].Doc + " score=" + hits[i].Score);
continue;
}
Document doc = searcher.Doc(hits[i].Doc);
String path = doc.Get("path");
if (path != null)
{
Console.Out.WriteLine((i + 1) + ". " + path);
String title = doc.Get("title");
if (title != null)
{
Console.Out.WriteLine(" Title: " + doc.Get("title"));
}
}
else
{
Console.Out.WriteLine((i + 1) + ". " + "No path for this document");
}
}
if (!interactive)
{
break;
}
if (numTotalHits >= end)
{
bool quit = false;
while (true)
{
Console.Out.Write("Press ");
if (start - hitsPerPage >= 0)
{
Console.Out.Write("(p)revious page, ");
}
if (start + hitsPerPage < numTotalHits)
{
Console.Out.Write("(n)ext page, ");
}
Console.Out.WriteLine("(q)uit or enter number to jump to a page.");
String line = input.ReadLine();
if (String.IsNullOrEmpty(line) || line[0] == 'q')
{
quit = true;
break;
}
if (line[0] == 'p')
{
start = Math.Max(0, start - hitsPerPage);
break;
}
//.........这里部分代码省略.........
示例11: 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;
// make sure document field doens't exist, if it does, simply add another value
if (doc.ContainsKey(field.Name))
{
var existingField = doc[field.Name] as DocumentField;
if (existingField != null)
existingField.AddValue(field.StringValue);
}
else // add new
{
doc.Add(new DocumentField(field.Name, field.StringValue));
}
}
}
}
entries.Add(doc);
}
var searchDocuments = new ResultDocumentSet
{
Name = "Items",
Documents = entries.ToArray(),
TotalCount = totalCount
};
Results.Documents = new[] { searchDocuments };
}
示例12: EnumSearchResults
private IEnumerable<ContentSearchResult> EnumSearchResults(int start, Searcher searcher, TopDocsCollector collector, int limit)
{
TopDocs results = collector.TopDocs();
float max = results.GetMaxScore();
ScoreDoc[] found = results.scoreDocs;
limit = Math.Min(limit, found.Length);
for (int i = start; i < limit; i++)
{
ScoreDoc doc = found[i];
Document docInfo = searcher.Doc(doc.doc);
ContentSearchResult.Builder builder = new ContentSearchResult.Builder();
builder.SetRanking((uint) Math.Max(0, Math.Min(100, (int) (doc.score/max*100f))));
builder.SetUri(docInfo.GetField("uri").StringValue());
builder.SetTitle(docInfo.GetField("title").StringValue());
builder.SetBlurb(docInfo.GetField("blurb").StringValue());
builder.SetModified(DateTime.ParseExact(docInfo.GetField("modified").StringValue(),
"yyyy-MM-dd HH:mm:ss", CultureInfo.InvariantCulture,
DateTimeStyles.None));
ContentRecord record;
if (TryGetValue(builder.Uri, out record))
{
builder.SetRecord(record);
}
yield return builder.Build();
}
}