In lucene.net can we search for a content without giving field name..and it will search in all fields that are indexed?

自闭症网瘾萝莉.ら 提交于 2019-12-09 14:35:01

问题


In lucene.net can we search for a content without giving field name..and it will search in all fields that are indexed.


回答1:


You cannot search for content without giving field name, however you can use MultiFieldQueryParser to search in all available fields.

E.g

Dim queryParser = New MultiFieldQueryParser(Version.LUCENE_29, _
    indexReader__1.GetFieldNames(IndexReader.FieldOption.ALL).ToArray(), analyzer)

here is complete an example.

'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

hope that help




回答2:


It will search all fields which are specified in the schema as searched by default.




回答3:


Use MultiFieldQueryParser to parse your queries, and provide it with a array of the field names you want searched.

The query doesn't need any special syntax. If your query is "cat hat" it will search all the specified fields for either of these terms. If your default operator is AND, it will require that each term be found in at least one field.



来源:https://stackoverflow.com/questions/1186790/in-lucene-net-can-we-search-for-a-content-without-giving-field-name-and-it-will

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!