Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to search across all the fields?

Tags:

In Lucene, we can use TermQuery to search a text with a field. I am wondering how to search a keyword across a bunch of fields or all the searchable fields?

like image 823
Adam Lee Avatar asked Mar 02 '13 02:03

Adam Lee


1 Answers

Another approach, which doesn't require to index anything more than what you already have, nor to combine different queries, is using the MultiFieldQueryParser.

You can provide a list of fields where you want to search on and your query, that's all.

MultiFieldQueryParser queryParser = new MultiFieldQueryParser(                 Version.LUCENE_41,                  new String[]{"title", "content", "description"},                 new StandardAnalyzer(Version.LUCENE_41));  Query query = queryParser.parse("here goes your query"); 

This is how I would do it with the original lucene library written in Java. I'm not sure whether the MultiFieldQueryParser is available in lucene.net too.

like image 152
javanna Avatar answered Oct 21 '22 07:10

javanna