本文介绍了我们可以在lucene.net中搜索内容而无需给出字段名称..并且它将在所有被索引的字段中进行搜索吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
在lucene.net中,我们可以在不提供字段名称的情况下搜索内容.它将在所有已索引的字段中进行搜索.
In lucene.net can we search for a content without giving field name..and it will search in all fields that are indexed.
推荐答案
您不能在不提供字段名称的情况下搜索内容,但是您可以使用MultiFieldQueryParser在所有可用字段中进行搜索.
You cannot search for content without giving field name, however you can use MultiFieldQueryParser to search in all available fields.
例如
Dim queryParser = New MultiFieldQueryParser(Version.LUCENE_29, _
indexReader__1.GetFieldNames(IndexReader.FieldOption.ALL).ToArray(), analyzer)
这是一个完整的示例.
'get index directory
Dim directory As Directory = FSDirectory.Open(New DirectoryInfo(HostingEnvironment.MapPath(VirtualIndexPath)))
'get analyzer
Dim analyzer As Analyzer = New StandardAnalyzer(Version.LUCENE_29)
'get index reader and searcher
Dim indexReader__1 As IndexReader = IndexReader.Open(directory, True)
Dim indexSearch As Searcher = New IndexSearcher(indexReader__1)
'add all possible fileds in multifieldqueryparser using indexreader getFieldNames method
Dim queryParser = New MultiFieldQueryParser(Version.LUCENE_29, _
indexReader__1.GetFieldNames(IndexReader.FieldOption.ALL).ToArray(), analyzer)
Dim query = queryParser.Parse(Criteria)
Dim resultDocs As TopDocs = Nothing
'perform search
resultDocs = indexSearch.Search(query, indexReader__1.MaxDoc())
Dim hits = resultDocs.scoreDocs
希望有帮助
这篇关于我们可以在lucene.net中搜索内容而无需给出字段名称..并且它将在所有被索引的字段中进行搜索吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!