I changed the QueryParser function to BooleanParser and now I'm getting no results AT ALL!
Here's my old code:
Code:
queryStr = queryStr.append("businessAddresses.address.cityName:\"" + criteria_.cityName.trim() + "\"~ ");
queryStr = queryStr.append(" AND businessAddresses.address.state:" + criteria_.stateName);
//queryStr = queryStr.append(" AND businessAccountStatuses.accountStatus:" + PBConstants.ACTIVE );
queryStr = queryStr.append(" AND businessServiceCategories.serviceCategory.serviceCategoryId:" + criteria_.categoryCode );
queryStr = queryStr.append(" AND ( businessName:" + keywords + "~");
queryStr = queryStr.append(" OR businessServices.service.serviceName:" + keywords + "~");
queryStr = queryStr.append(" OR businessSubCategories.serviceSubCategory.serviceSubCategoryName:" + keywords + "~");
queryStr = queryStr.append(" ) ");
org.apache.lucene.search.Query query = parser.parse(queryStr.toString());
Criteria criteria = fullTextSession.createCriteria( BusinessCbo.class )
.setFetchMode( "businessAddresses", FetchMode.JOIN )
.setFetchMode( "businessServiceCategories", FetchMode.JOIN )
.setFetchMode( "businessServices", FetchMode.JOIN )
.setFetchMode( "businessSubCategories", FetchMode.JOIN )
.setFetchMode( "businessAccountStatuses", FetchMode.JOIN );
searchQry = fullTextSession.createFullTextQuery( query ).setCriteriaQuery( criteria );
Here's the new code:
Code:
PhraseQuery phraseQryBiz = new PhraseQuery();
PhraseQuery phraseQrySubCat = new PhraseQuery();
PhraseQuery phraseQrySrv = new PhraseQuery();
FuzzyQuery fuzzyQryCity = new FuzzyQuery(new Term("businessAddresses.address.cityName", criteria_.cityName.trim()));
TermQuery stateQuery = new TermQuery(new Term("businessAddresses.address.state", criteria_.stateName.trim()));
TermQuery catQuery = new TermQuery(new Term("businessServiceCategories.serviceCategory.serviceCategoryId", criteria_.categoryCode.trim() ));
FuzzyQuery fuzzyQryBiz = new FuzzyQuery(new Term("businessName", keywords.trim() ));
FuzzyQuery fuzzyQrySrv = new FuzzyQuery(new Term("businessServices.service.serviceName", keywords.trim() ));
FuzzyQuery fuzzyQrySub = new FuzzyQuery(new Term("businessSubCategories.serviceSubCategory.serviceSubCategoryName", keywords.trim() ));
BooleanQuery query = new BooleanQuery();
query.add(fuzzyQryCity, BooleanClause.Occur.MUST);
query.add(stateQuery, BooleanClause.Occur.MUST);
query.add(catQuery, BooleanClause.Occur.MUST);
query.add(fuzzyQryBiz, BooleanClause.Occur.SHOULD);
query.add(fuzzyQrySrv, BooleanClause.Occur.SHOULD);
query.add(fuzzyQrySub, BooleanClause.Occur.SHOULD);
Criteria criteria = fullTextSession.createCriteria( BusinessCbo.class )
.setFetchMode( "businessAddresses", FetchMode.JOIN )
.setFetchMode( "businessServiceCategories", FetchMode.JOIN )
.setFetchMode( "businessServices", FetchMode.JOIN )
.setFetchMode( "businessSubCategories", FetchMode.JOIN )
.setFetchMode( "businessAccountStatuses", FetchMode.JOIN );
searchQry = fullTextSession.createFullTextQuery( query ).setCriteriaQuery( criteria );
What I'm I doing wrong?