I'm new to Lucene and i'm doing hibernate search for two fields for a employee class and the fields are emp_name and emp_address but using this code
Session session = HibernateUtil.getSessionFactory().openSession();
FullTextSession fullTextSession = Search.getFullTextSession(session);
SearchFactory searchFactory = fullTextSession.getSearchFactory();
String testString = "\"karthick\" AND \"tn\"";
//String testString = '+'+"karthick AND tn";
System.out.println(testString);
String[] fields={"emp_name","emp_address"};
/* Creating the Lucene Query */
FullTextSession fSession = Search.getFullTextSession(session);
fSession.beginTransaction();
Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_CURRENT);
QueryBuilder mythQB = searchFactory.buildQueryBuilder().forEntity( EmpVo.class ).get();
Query luceneQuery = mythQB.keyword().onFields("emp_name","emp_address").matching(testString).createQuery();
org.hibernate.Query fullTextQuery = fullTextSession.createFullTextQuery( luceneQuery );
List<EmpVo> result = fullTextQuery.list();
for (EmpVo employee : result) {
System.out.println(employee.getEmp_name()+"------"+employee.getEmp_telno()+"------"+employee.getEmp_address());
}
I need to get only the result for the employee name karthick and employee address tn
,but
for me i'm getting the result like this
karthick------137594------tn
guna------134679------tn
chandra------246810------tn