Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

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.

like image 570
devson Avatar asked Jul 27 '09 06:07

devson


2 Answers

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

like image 158
vijay shiyani Avatar answered Sep 27 '22 21:09

vijay shiyani


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

like image 40
Kevin Peterson Avatar answered Sep 27 '22 19:09

Kevin Peterson