Reputation: 1
I use hibernate search 4.2.0 with hibernate 4.2.15 and spring 3.2.10. I have a strange behavior when a use an hibernate search (lucene) query.
In the database I've this value for the field content : "méchant". When I make a query with "mechant" it works fine, I get the objet. But when I use "méchant" it doesn't work...
The Mapping :
@Entity
@Indexed
@AnalyzerDef(name = "customAnalyzer",
tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class)
})
@Table(name = "MESSAGE")
public class Message {
...
@Id
@DocumentId
@GeneratedValue
@Column(name = "ID_MESSAGE")
public Integer getId() {
return id;
}
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
@Analyzer(definition="customAnalyzer")
@Column(name = "CONTENT", length = 65535, columnDefinition = "Text")
public String getContent() {
return content;
}
...
]
The hibernate config :
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
<property name="dataSource" ref="customDataSource" />
<property name="hibernateProperties">
<props>
<prop key="hibernate.bytecode.provider">javassist</prop>
<prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
<prop key="hibernate.show_sql">${hibernate.showSql}</prop>
<prop key="hibernate.hbm2ddl.auto">validate</prop>
<prop key="hibernate.search.default.directory_provider">filesystem</prop>
<prop key="hibernate.search.default.indexBase">${indexLucene.path}</prop>
</props>
</property>
</bean>
The query :
FullTextSession searchSession = Search.getFullTextSession(getSessionFactory().getCurrentSession());
QueryBuilder qb = searchSession.getSearchFactory().buildQueryBuilder().forEntity(Message.class).get();
BooleanJunction<BooleanJunction> bool = qb.bool();
...
bool.must(qb.keyword().boostedTo(4f)
.onFields("content")
.matching(messageCriteria.getQuery())
.createQuery());
...
org.apache.lucene.search.Query luceneQuery =bool.createQuery();
FullTextQuery jpaQuery = searchSession.createFullTextQuery(luceneQuery, Message.class);
Is that somebody can help me?
[EDIT] Thank you all, I solved the problem : It wasn't due to hibernate search but the charset of my http request. I'll check how to fix my charset issue. Sorry for the waste of time...
Upvotes: 0
Views: 1177
Reputation: 19129
In your example you are just using SnowballPorterFilterFactory
without specifying the language parameter. This defaults to English, which is probably not what you want. Have you tried changing this to the language you are targeting?
Upvotes: 0