java - Hibernate Search behaves differently between DEV and PROD with same databse -
i have 1 domain object needs indexed hibernate search. when fulltextquery on object on dev machine, expected results. deploy app war , explode prod server (a vps). when perform same "search" on prod machine, don't expected results @ (it seems results missing).
i've run luke ensure indexed, , appears should be... i'm new hibernate search, appreciated.
here's domain object:
package com.chatter.domain; import javax.persistence.cascadetype; import javax.persistence.column; import javax.persistence.entity; import javax.persistence.fetchtype; import javax.persistence.generatedvalue; import javax.persistence.generationtype; import javax.persistence.id; import javax.persistence.joincolumn; import javax.persistence.manytoone; import javax.persistence.table; import org.apache.solr.analysis.lowercasefilterfactory; import org.apache.solr.analysis.snowballporterfilterfactory; import org.apache.solr.analysis.standardtokenizerfactory; import org.hibernate.search.annotations.analyzerdef; import org.hibernate.search.annotations.field; import org.hibernate.search.annotations.index; import org.hibernate.search.annotations.indexed; import org.hibernate.search.annotations.indexedembedded; import org.hibernate.search.annotations.parameter; import org.hibernate.search.annotations.store; import org.hibernate.search.annotations.tokenfilterdef; import org.hibernate.search.annotations.tokenizerdef; @entity @table(name="faq") @indexed() @analyzerdef(name = "customanalyzer", tokenizer = @tokenizerdef(factory = standardtokenizerfactory.class), filters = { @tokenfilterdef(factory = lowercasefilterfactory.class), @tokenfilterdef(factory = snowballporterfilterfactory.class, params = { @parameter(name = "language", value = "english") }) }) public class customerfaq implements comparable<customerfaq> { private long id; @indexedembedded private customer customer; @field(index=index.tokenized, store=store.no) private string question; @field(index=index.tokenized, store=store.no) private string answer; @id @generatedvalue(strategy = generationtype.auto) public long getid() { return id; } public void setid(long id) { this.id = id; } @manytoone(fetch=fetchtype.eager, cascade=cascadetype.all) @joincolumn(name="customer_id") public customer getcustomer() { return customer; } public void setcustomer(customer customer) { this.customer = customer; } @column(name="question", length=1500) public string getquestion() { return question; } public void setquestion(string question) { this.question = question; } @column(name="answer", length=1500) public string getanswer() { return answer; } public void setanswer(string answer) { this.answer = answer; } @override public int hashcode() { final int prime = 31; int result = 1; result = prime * result + ((id == null) ? 0 : id.hashcode()); return result; } @override public boolean equals(object obj) { if (this == obj) return true; if (obj == null) return false; if (getclass() != obj.getclass()) return false; customerfaq other = (customerfaq) obj; if (id == null) { if (other.id != null) return false; } else if (!id.equals(other.id)) return false; return true; } @override public int compareto(customerfaq o) { if (this.getcustomer().equals(o.getcustomer())) { return this.getid().compareto(o.getid()); } else { return this.getcustomer().getid().compareto(o.getcustomer().getid()); } } }
here's snippet of customer domain object:
import org.hibernate.search.annotations.field; import org.hibernate.search.annotations.index; import org.hibernate.search.annotations.store; import javax.persistence.entity; // ... other imports @entity public class customer { @field(index=index.tokenized, store=store.yes) private long id; // ... other instance vars @id @generatedvalue(strategy = generationtype.auto) public long getid() { return id; } public void setid(long id) { this.id = id; }
and persistence.xml:
<?xml version="1.0" encoding="utf-8" standalone="no"?> <persistence xmlns="http://java.sun.com/xml/ns/persistence" xmlns:xsi="http://www.w3.org/2001/xmlschema-instance" version="2.0" xsi:schemalocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd"> <persistence-unit name="persistenceunit" transaction-type="resource_local"> <provider>org.hibernate.ejb.hibernatepersistence</provider> <properties> <property name="hibernate.dialect" value="org.hibernate.dialect.mysql5innodbdialect"/> <!-- value="create" build new database on each run; value="update" modify existing database; value="create-drop" means same "create" drops tables when hibernate closes; value="validate" makes no changes database --> <property name="hibernate.hbm2ddl.auto" value="update"/> <property name="hibernate.ejb.naming_strategy" value="org.hibernate.cfg.improvednamingstrategy"/> <property name="hibernate.connection.charset" value="utf-8"/> <!-- hibernate search configuration --> <property name="hibernate.search.default.directory_provider" value="filesystem" /> <property name="hibernate.search.default.indexbase" value="c:/lucene/indexes" /> </properties> </persistence-unit> </persistence>
and finally, here's query that's being used in dao:
public list<customerfaq> searchfaqs(string question, customer customer) { fulltextsession fulltextsession = search.getfulltextsession(sessionfactory.getcurrentsession()); querybuilder querybuilder = fulltextsession.getsearchfactory().buildquerybuilder().forentity(customerfaq.class).get(); org.apache.lucene.search.query lucenequery = querybuilder.keyword().onfields("question", "answer").matching(question).createquery(); org.hibernate.query fulltextquery = fulltextsession.createfulltextquery(lucenequery, customerfaq.class); list<customerfaq> matchingquestionslist = fulltextquery.list(); log.debug("found " + matchingquestionslist.size() + " matching questions"); list<customerfaq> list = new arraylist<customerfaq>(); (customerfaq customerfaq : matchingquestionslist) { log.debug("comparing " + customerfaq.getcustomer() + " " + customer + " -> " + customerfaq.getcustomer().equals(customer)); log.debug("does list contain customer faq? " + list.contains(customerfaq)); if (customerfaq.getcustomer().equals(customer) && !list.contains(customerfaq)) { list.add(customerfaq); } } log.debug("returning " + list.size() + " matching questions based on customer: " + customer); return list; }
it looks actual location software looking indexbase incorrect.
when looked through logs, noticed referring 2 different locations when loading indexbase.
one location hibernate search loading indexbase "c:/program files/apache software foundation/tomcat 6.0/tmp/indexes", little later on in logs (during startup phase) saw loading place had set in persistence.xml file ("c:/lucene/indexes").
so realizing this, changed location in persistence.xml file match location (for reason) looking. once 2 matched up, bingo, worked!
Comments
Post a Comment