Return Lucene field name when a query is matched
So I am using the MultiFieldQueryParser in Lucene 3.0.2, and I have given it multiple fields. I want to find out which field matched the query; I searched on here, and one user said there is absolutely no way to do this. Is this really true? If so, can anyo开发者_StackOverflow中文版ne recommend a way around this or another system that would allow me to do this?
I can put the entire document in one field, "contents" for example, but I think this makes the problem even worse.
I want to query a database with, for example, Brad, and see whether the query came from a movie name, an actor's name, a director's name, etc. etc.
Thank you
I would strongly recommend the use of BooleanQuery with stnadard QueryParser:
BooleanQuery booleanQuery = new BooleanQuery();
FuzzyQuery field1Query = new FuzzyQuery(new Term("field1", searchTerm), 0.3f, 1, 10);
FuzzyQuery field2Query = new FuzzyQuery(new Term("field2", searchTerm), 0.3f, 1, 10);
booleanQuery.add(field1Query , BooleanClause.Occur.SHOULD);
booleanQuery.add(field1Query , BooleanClause.Occur.SHOULD);
This way you can perform search on exactly the fields you want and adjust it to produce fine tuned results. Assuming that is your ultimate goal.
精彩评论