Hello,
I'm a bit new to Hibernate and Hibernate Search, and I'm having a problem getting my full text search to work across fields in the database.
My table looks like this:
Code:
create table Entry (
entry_id bigint unsigned not null auto_increment,
category_id smallint unsigned not null,
entry_title varchar(300) not null,
entry_question text not null,
entry_answer text not null,
entry_hitcount bigint unsigned not null,
contact_id smallint unsigned not null default 0,
primary key(entry_id)
) engine = MyISAM;
(The important fields are entry_title, entry_question, entry_answer, everything else works)
I've configured the appropriate listeners in my Hibernate.cfg file, so entries are getting indexed upon insertion, but when I try to search the entries with the code below, I sometimes get duplicate results.
Code:
private Collection<Entry> query() {
MultiFieldQueryParser mpq = new MultiFieldQueryParser(FIELDS, new StandardAnalyzer());
Query q;
try {
q = mpq.parse(query);
begin();
org.hibernate.Query hQ = session.createFullTextQuery(q, Entry.class);
Collection<Entry> results = hQ.list();
end();
return results;
} catch (ParseException ex) {
ex.printStackTrace();
return null;
}
}
For example: If I create a new entry through the application with the values
entry_title: Test title
entry_question: Pandora or Imeem?
entry_question: this is a pretty nifty question. No music for you!
and search for "test" I get two results back, even if that's the only entry in the database.
What would be the correct way to perform an AND search across those 3 fields?
Thanks in advance! (Hope it's not a duplicate question, I swear I searched!)