How to make a multipolar field - phrase search in Lucene?

The name asks for all this ... I want to do a multi-user search in Lucene .. How do I do this?

for example: I have fields like String s[] = {"title","author","content"};
I want to search harry potterin all fields .. How do I do this?

Can someone provide an example snippet?

+3
source share
2 answers
  • Use MultiFieldQueryParserits QueryParser, which creates queries to search for multiple fields. .

  • Another way is to use Create BooleanQuery consisting of TermQurey (in your case, a query phrase).

  • The third way is to include the contents of other fields in the content field default.


Add

. , , , , .


:

Query query = MultiFieldQueryParser.parse(Version.LUCENE_30, new String[] {"harry potter","harry potter","harry potter"},   new String[] {"title","author","content"},new SimpleAnalyzer());
IndexSearcher searcher = new IndexSearcher(...);
Hits hits = searcher.search(query);

MultiFieldQueryParser : (. javadoc)

, . x :

(field1: query1) (field2: query2) (Field3: query3)... (fieldx: queryx)

, .

+4

Source: https://habr.com/ru/post/1794333/


All Articles