You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@lucene.apache.org by Jamil Marques Figueira Junior <ja...@gmail.com> on 2009/06/08 22:51:29 UTC

How to know in the returned documents of a query had match in a specific field

Hello,

    I wold like to know if any document returned from my search query had
match in a specific field. Example:

Documents:
Field 1 - Company Name
Field 2 - Street

Document1 (CompanyName = "metalpack corp", Street = "Route 66")
Document2 (CompanyName = "ibi Bank", Street = "metalpack")

If I create a query like this:
BooleanQuery bq = new BooleanQuery();
TermQuery companyNameTermQuery = new TermQuery(new Term("CompanyName",
"metalpack"))
TermQuery streetTermQuery = new TermQuery(new Term("Street", "metalpack"))
bq.add(companyNameTermQuery, BooleanClause.Occur.SHOULD);
bq.add(streetTermQuery , BooleanClause.Occur.SHOULD);
IndexSearcher is = new IndexSearcher(myRAMDirectory);
is.search(bq);

the query above will return both document of my index, but how can I know if
the result has documents that the matching field was the CompanyName without
read all the document results?


-- 
tks,

Jamil