In lucene.net can we search for a content without giving field name..and it will search in all fields that are indexed.
在lucene.net中,我们可以在不提供字段名称的情况下搜索内容。它将搜索所有已编制索引的字段。
3 个解决方案
#1
You cannot search for content without giving field name, however you can use MultiFieldQueryParser to search in all available fields.
您不能在不提供字段名称的情况下搜索内容,但是您可以使用MultiFieldQueryParser搜索所有可用字段。
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.
使用MultiFieldQueryParser解析查询,并为其提供要搜索的字段名称数组。
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.
查询不需要任何特殊语法。如果您的查询是“cat hat”,它将搜索所有指定字段中的任何一个术语。如果您的默认运算符是AND,则需要在至少一个字段中找到每个术语。
#1
You cannot search for content without giving field name, however you can use MultiFieldQueryParser to search in all available fields.
您不能在不提供字段名称的情况下搜索内容,但是您可以使用MultiFieldQueryParser搜索所有可用字段。
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.
使用MultiFieldQueryParser解析查询,并为其提供要搜索的字段名称数组。
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.
查询不需要任何特殊语法。如果您的查询是“cat hat”,它将搜索所有指定字段中的任何一个术语。如果您的默认运算符是AND,则需要在至少一个字段中找到每个术语。