本文整理汇总了C#中Lucene.Net.Search.IndexSearcher.Doc方法的典型用法代码示例。如果您正苦于以下问题:C# IndexSearcher.Doc方法的具体用法?C# IndexSearcher.Doc怎么用?C# IndexSearcher.Doc使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Lucene.Net.Search.IndexSearcher
的用法示例。
在下文中一共展示了IndexSearcher.Doc方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Search
public ActionResult Search(string query)
{
ViewData["Message"] = "query : " + query;
var searcher = new IndexSearcher(
new Lucene.Net.Store.SimpleFSDirectory(new DirectoryInfo(Configuration.IndexDirectory)),
readOnly: true);
var fieldsToSearchIn = new[] {Configuration.Fields.Name, Configuration.Fields.Description};
var queryanalizer = new MultiFieldQueryParser(Version.LUCENE_CURRENT,
fieldsToSearchIn,
new BrazilianAnalyzer());
var numberOfResults = 10;
var top10Results = searcher.Search(queryanalizer.Parse(query), numberOfResults);
var docs = new List<DocumentViewModel>();
foreach (var scoreDoc in top10Results.scoreDocs)
{
var document = searcher.Doc(scoreDoc.doc);
var name = document.GetField(Configuration.Fields.Name).StringValue();
var description = document.GetField(Configuration.Fields.Description).StringValue();
var link = document.GetField(Configuration.Fields.Link).StringValue();
docs.Add(new DocumentViewModel(name, description, link));
}
return View(new SearchViewModel(docs));
}
示例2: Execute
public static ICollection<SearchResult> Execute(string query)
{
ICollection<SearchResult> searchResults = new List<SearchResult>();
string directoryPath = AppDomain.CurrentDomain.BaseDirectory + @"\App_Data\LuceneIndexes";
var directory = FSDirectory.Open(directoryPath);
var analyzer = new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30);
var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "SearchBody", analyzer);
Query searchQuery = parser.Parse(query + "*");
IndexSearcher searcher = new IndexSearcher(directory);
TopDocs hits = searcher.Search(searchQuery, 200);
int results = hits.ScoreDocs.Length;
for (int i = 0; i < results; i++)
{
Document doc = searcher.Doc(hits.ScoreDocs[i].Doc);
var searchResult = new SearchResult();
searchResult.EntityId = int.Parse(doc.Get("EntityId"));
searchResult.EntityTypeName = doc.Get("EntityTypeName");
searchResult.SearchTitle = doc.Get("SearchTitle");
searchResult.SearchBody = doc.Get("SearchBody");
searchResults.Add(searchResult);
}
searcher.Dispose();
directory.Dispose();
return searchResults;
}
示例3: Search
public IList<SearchDocument> Search(IList<Filter> searchFilters, IList<SearchSortField> sortFields)
{
if (searchFilters == null || searchFilters.Count == 0)
return new List<SearchDocument>();
var sort = CreateSort(searchFilters, sortFields);
var reader = IndexReader.Open(_directory, true);
var searcher = new IndexSearcher(reader);
var query = CreateQuery(searchFilters);
var hits = searcher.Search(query, new QueryWrapperFilter(query), 100, sort);
var searchResult = new List<SearchDocument>();
foreach (var facet in hits.ScoreDocs)
{
var doc = searcher.Doc(facet.Doc);
var searchDoc = new SearchDocument
{
Fields = new List<SearchDocumentField>()
};
var docFields = doc.GetFields();
foreach (var field in docFields)
{
var value = doc.Get(field.Name);
searchDoc.Fields.Add(new SearchDocumentField {FieldName = field.Name, Value = value});
}
searchResult.Add(searchDoc);
}
return searchResult;
}
示例4: FuzzyQueryTest
public void FuzzyQueryTest()
{
string titulo = "titulo";
string texto = "texto";
using (var diretorio = new RAMDirectory())
{
IndexarArquivosEmDocumento(diretorio, new Field[]
{
new Field(titulo, "fuzzy", Field.Store.YES, Field.Index.ANALYZED),
new Field(titulo, "wuzzy", Field.Store.YES, Field.Index.ANALYZED)
});
using (var searcher = new IndexSearcher(diretorio, true))
{
var query = new FuzzyQuery(new Term(titulo, "wuzza"));
var matches = searcher.Search(query, 10);
Assert.AreEqual(2, matches.TotalHits, "both close enough");
Assert.IsTrue(matches.ScoreDocs[0].Score != matches.ScoreDocs[1].Score, "wuzzy closer then fuzzy");
var doc = searcher.Doc(matches.ScoreDocs[0].Doc);
Assert.AreEqual("wuzzy", doc.Get(titulo), "wazza bear");
}
}
}
示例5: SearchCore
private static IList<int> SearchCore(SearchFilter searchFilter, out int totalHits)
{
if (!Directory.Exists(LuceneCommon.IndexDirectory))
{
totalHits = 0;
return new int[0];
}
SortField sortField = GetSortField(searchFilter);
int numRecords = searchFilter.Skip + searchFilter.Take;
using (var directory = new LuceneFileSystem(LuceneCommon.IndexDirectory))
{
var searcher = new IndexSearcher(directory, readOnly: true);
var query = ParseQuery(searchFilter);
var filterTerm = searchFilter.IncludePrerelease ? "IsLatest" : "IsLatestStable";
var termQuery = new TermQuery(new Term(filterTerm, Boolean.TrueString));
Filter filter = new QueryWrapperFilter(termQuery);
var results = searcher.Search(query, filter: filter, n: numRecords, sort: new Sort(sortField));
var keys = results.scoreDocs.Skip(searchFilter.Skip)
.Select(c => ParseKey(searcher.Doc(c.doc).Get("Key")))
.ToList();
totalHits = results.totalHits;
searcher.Close();
return keys;
}
}
示例6: Query
public Task<List<TestDocument>> Query(string q)
{
QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "text", Analyzer);
Query query = parser.Parse(q);
IndexSearcher searcher = new IndexSearcher(Index, true);
//Do the search
TopDocs docs = searcher.Search(query, 10);
int results = docs.TotalHits;
List<TestDocument> ret = new List<TestDocument>();
for (int i = 0; i < results; i++)
{
ScoreDoc d = docs.ScoreDocs[i];
float score = d.Score;
Document idoc = searcher.Doc(d.Doc);
ret.Add(new TestDocument()
{
Id = Convert.ToInt32(idoc.GetField("id").StringValue),
Text = idoc.GetField("text").StringValue
});
}
searcher.Dispose();
return Task.FromResult(ret);
}
示例7: SearchBIMXchange
public static LuceneResult SearchBIMXchange(string field, string key, int pageSize, int pageNumber)
{
const string luceneIndexPath = "C:\\LuceneIndex";
var directory = FSDirectory.Open(new DirectoryInfo(luceneIndexPath));
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var parser = new QueryParser(Version.LUCENE_29, field, analyzer);
var query = parser.Parse(String.Format("{0}*", key));
var searcher = new IndexSearcher(directory, true);
var topDocs = searcher.Search(query, 1000000);
var docs = new List<Document>();
var start = (pageNumber-1)*pageSize;
for (var i = start; i < start + pageSize && i < topDocs.TotalHits; i++)
{
var scoreDoc = topDocs.ScoreDocs[i];
var docId = scoreDoc.doc;
var doc = searcher.Doc(docId);
docs.Add(doc);
}
searcher.Close();
directory.Close();
var result = new LuceneResult {Results = docs, TotalCount = topDocs.TotalHits};
return result;
}
示例8: ConvertToDataTable
private static DataTable ConvertToDataTable(IndexSearcher indexSearcher, ScoreDoc[] result)
{
DataTable dt = new DataTable();
dt.Columns.Add(new DataColumn(LuceneConfig.Field_Path));
dt.Columns.Add(new DataColumn(LuceneConfig.Field_FileName));
dt.Columns.Add(new DataColumn(LuceneConfig.Field_PageNumber));
dt.Columns.Add(new DataColumn(LuceneConfig.Field_ContentByPage));
dt.Columns.Add(new DataColumn(LuceneConfig.Field_Score));
foreach (ScoreDoc scoreDoc in result)
{
Document doc = indexSearcher.Doc(scoreDoc.Doc);
DataRow dr = dt.NewRow();
dr[LuceneConfig.Field_Path] = doc.Get(LuceneConfig.Field_Path);
dr[LuceneConfig.Field_FileName] = doc.Get(LuceneConfig.Field_FileName);
dr[LuceneConfig.Field_PageNumber] = doc.Get(LuceneConfig.Field_PageNumber);
dr[LuceneConfig.Field_ContentByPage] = doc.Get(LuceneConfig.Field_ContentByPage);
dr[LuceneConfig.Field_Score] = scoreDoc.Score;
dt.Rows.Add(dr);
}
return dt;
}
示例9: Search
IEnumerable<string> Search(string textToFind)
{
var reader = IndexReader.Open(_ramDirectory, true);
var searcher = new IndexSearcher(reader);
var analyzer = new StandardAnalyzer(Version.LUCENE_29);
var parser = new MultiFieldQueryParser(Version.LUCENE_29, _searchFields, analyzer);
var query = parser.Parse(textToFind);
var collector = TopScoreDocCollector.create(100, true);
searcher.Search(query, collector);
var hits = collector.TopDocs().scoreDocs;
var foundKeys = new List<string>();
foreach (ScoreDoc scoreDoc in hits)
{
var document = searcher.Doc(scoreDoc.doc);
var key = document.Get(_keyField);
if (key != null && !foundKeys.Contains(key))
{
foundKeys.Add(key);
}
}
reader.Close();
searcher.Close();
analyzer.Close();
return foundKeys;
}
示例10: MultiSearchBIMXchange
public static LuceneResult MultiSearchBIMXchange(Dictionary<string,string> terms, int pageSize, int pageNumber)
{
var directory = FSDirectory.Open(new DirectoryInfo("LuceneIndex"));
var booleanQuery = new BooleanQuery();
foreach(var term in terms)
{
var query = new TermQuery(new Term(term.Key, term.Value));
booleanQuery.Add(query,BooleanClause.Occur.MUST);
}
var searcher = new IndexSearcher(directory, true);
var topDocs = searcher.Search(booleanQuery, 10);
var docs = new List<Document>();
var start = (pageNumber - 1) * pageSize;
for (var i = start; i < start + pageSize && i < topDocs.TotalHits; i++)
{
var scoreDoc = topDocs.ScoreDocs[i];
var docId = scoreDoc.doc;
var doc = searcher.Doc(docId);
docs.Add(doc);
}
searcher.Close();
directory.Close();
var result = new LuceneResult {Results = docs, TotalCount = topDocs.TotalHits};
return result;
}
示例11: Search
public SearchResults Search(DocumentRoot root, string term)
{
var results = new SearchResults();
var indexPath = _settings.GetSearchIndexPath();
var version = Lucene.Net.Util.Version.LUCENE_30;
using (var directory = FSDirectory.Open(new DirectoryInfo(indexPath)))
using (var indexReader = IndexReader.Open(directory, true))
using (var indexSearch = new IndexSearcher(indexReader))
{
var analyzer = new StandardAnalyzer(version);
var queryParser = new MultiFieldQueryParser(version, new[] { "Title", "Body" }, analyzer);
var query = queryParser.Parse(term);
var resultDocs = indexSearch.Search(query, indexReader.MaxDoc);
var hits = resultDocs.ScoreDocs;
foreach (var hit in hits)
{
var doc = indexSearch.Doc(hit.Doc);
results.Documents.Add(new SearchResult
{
Score = hit.Score,
Snippet = doc.Get("Snippet"),
Title = doc.Get("Title")
});
}
}
return results;
}
示例12: AiComplete
public List<int> AiComplete(string args)
{
List<int> list = new List<int>();
try
{
IndexReader citac = IndexReader.Open(this.folder, true);
var seracher = new IndexSearcher(citac);
var queryParser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "Content", new KeywordAnalyzer());
queryParser.AllowLeadingWildcard = true;
var query = queryParser.Parse(args+"*");
TopDocs result = seracher.Search(query, 5);
var lista = result.ScoreDocs;
foreach (var hint in lista)
{
var h = seracher.Doc(hint.Doc);
list.Add(h.Get("ArticlesID").ToInt());
}
}
catch (Exception)
{
}
return list;
}
示例13: readQuestionInput
static List<String[]> readQuestionInput(List<String> input)
{
List<String[]> results = new List<String[]>();
IndexReader indexReader = IndexReader.Open(directory, true);
Searcher indexSearch = new IndexSearcher(indexReader);
foreach (var keyword in input)
{
var query = createQuery("Content" , keyword , analyzer);
//var query = createBooleanQuery("Content", input);
//Console.WriteLine("Searching for : " + query);
TopDocs resultDocs = indexSearch.Search(query, indexReader.MaxDoc);
var hits = resultDocs.ScoreDocs;
foreach (var hit in hits)
{
var documentFromSearch = indexSearch.Doc(hit.Doc);
//results.Add(new String[]{ "Path: " , documentFromSearch.Get("Path")});
foreach (String[] result in ContentSpilt.indexof_withPro(input, documentFromSearch.Get("Content")))
{
String[] temp = new String[3];
temp[0] = documentFromSearch.Get("Subject") ;
temp[1] = result[0];
temp[2] = result[1];
results.Add(temp);
}
}
}
return results;
}
示例14: CanQueryLuceneIndexCreatedOnDisk
public void CanQueryLuceneIndexCreatedOnDisk()
{
CanCreateLuceneIndexOnDisk();
System.IO.DirectoryInfo di = new System.IO.DirectoryInfo(System.IO.Path.GetTempPath());
using (Lucene.Net.Store.Directory directory = Lucene.Net.Store.FSDirectory.Open(di))
{
Lucene.Net.Index.IndexReader ir = Lucene.Net.Index.IndexReader.Open(directory, true);
Lucene.Net.Search.Searcher searcher = new Lucene.Net.Search.IndexSearcher(ir);
using (Lucene.Net.Analysis.Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30))
{
Lucene.Net.QueryParsers.QueryParser parser = new Lucene.Net.QueryParsers.QueryParser(Version.LUCENE_30, "content", analyzer);
Lucene.Net.Search.Query query = parser.Parse("lorem");
Lucene.Net.Search.TopScoreDocCollector collector = Lucene.Net.Search.TopScoreDocCollector.Create(100, true);
searcher.Search(query, collector);
Lucene.Net.Search.ScoreDoc[] docs = collector.TopDocs().ScoreDocs;
foreach (Lucene.Net.Search.ScoreDoc scoreDoc in docs)
{
//Get the document that represents the search result.
Document document = searcher.Doc(scoreDoc.Doc);
var id = document.Get("Id");
var content = document.Get("content");
}
}
}
}
示例15: Search
public SearchResult[] Search(string searchString)
{
Analyzer analyzer = new Lucene.Net.Analysis.Standard.StandardAnalyzer(Version.LUCENE_29);
QueryParser parser = new QueryParser(Version.LUCENE_29, "Content", analyzer);
var query = parser.Parse(searchString);
Searcher searcher = new IndexSearcher(Lucene.Net.Index.IndexReader.Open(directory, true));
TopScoreDocCollector collector = TopScoreDocCollector.Create(100, true);
searcher.Search(query, collector);
var hits = collector.TopDocs().ScoreDocs;
List<SearchResult> results = new List<SearchResult>();
for (int i = 0; i < hits.Length; i++)
{
int docId = hits[i].Doc;
float score = hits[i].Score;
Lucene.Net.Documents.Document doc = searcher.Doc(docId);
results.Add(new SearchResult
{
BookId = Guid.Parse(doc.Get("BookId")),
Score = score
});
}
return results.ToArray();
}