Hi,
I am trying to combine an existing multiFieldQuery with another boolean query to form an AND clause. If I just use the
luceneQuery argument the results returned matches perfectly with what is returned in Luke. However with the code below, if I append/merge another query to the MultiFieldQueryParser string, the result size is zero though Luke returns back few record. Just want to know if we can merge a multiFieldQuery with another query. If yes, is this the proper way or I am missing out something.
Code:
public List<?> genericTPEmployeesSearch(String searchQuery, String clause, SearchBean bean){
String[] searchFields = getSearchFields();
FullTextSession ftSession = SessionUtil.getFullTextSessionInstance();
//Parser meant for using all the fields used for search
MultiFieldQueryParser multiQueryParser = new MultiFieldQueryParser(
searchFields, ftSession.getSearchFactory().getAnalyzer(TP_Employee.class));
if(clause.equals(and)){
multiQueryParser.setDefaultOperator(QueryParser.AND_OPERATOR);
} else {
multiQueryParser.setDefaultOperator(QueryParser.OR_OPERATOR);
}
try {
BooleanQuery luceneQuery = (BooleanQuery)multiQueryParser.parse(makeGenericQueryString(searchQuery));
org.apache.lucene.search.Query query1 = new TermQuery(new Term("busDivision", "Corporate center"));
BooleanQuery booleanQuery1 = new BooleanQuery();
booleanQuery1.add(query1, BooleanClause.Occur.SHOULD);
BooleanQuery[] booleanQueries = {booleanQuery1, luceneQuery};
//Returns results from index rather than database with fields as arg
List<Object[]> results = ftSession.createFullTextQuery(BooleanQuery.mergeBooleanQueries(booleanQueries), TP_Employee.class) .setProjection("emplid",
"busFirstName",
"busLastName",
"busEmailAdd",
"busPhone",
"lineManager",
"busDivision",
"busUnit",
"busArea",
"busSector",
"busSegment",
"location",
"country",
"city",
"state",
"busTitle",
"rankDesc",
"latestHireDate",
"profileUpdateDate",
"isHrbpHrm",
"education.description",
"education.accomplishmentCat",
"education.accomplishment",
FullTextQuery.SCORE)
.list();
return results;
} catch (ParseException e) {
e.printStackTrace();
}
return null;
}
--Manoj