Parses a query, searching on the fields specified.
Use this if you need to specify certain fields as required,
and others as prohibited.
Usage:
String[] fields = {"filename", "contents", "description"};
int[] flags = {MultiFieldQueryParser.NORMAL FIELD,
MultiFieldQueryParser.REQUIRED FIELD,
MultiFieldQueryParser.PROHIBITED FIELD,};
parse(query, fields, flags, analyzer);
The code above would construct a query:
(filename:query) +(contents:query) -(description:query)
BooleanQuery bQuery = new BooleanQuery();
for (int i = 0; i < fields.length; i++)
{
Query q = parse(query, fields[i], analyzer);
int flag = flags[i];
switch (flag)
{
case REQUIRED_FIELD:
bQuery.add(q, true, false);
break;
case PROHIBITED_FIELD:
bQuery.add(q, false, true);
break;
default:
bQuery.add(q, false, false);
break;
}
}
return bQuery;