我有一个名为'Patient'的字符串字段名为'firstName','lastName'和'secondLastName'的实体(在西班牙语中,我们同时使用父亲和母亲姓氏)Hibernate搜索:如何通过单独的列搜索全名
我有一个文本框按照名称搜索患者的视图,其中用户可以按任何给定顺序键入任何内容:firstName,lastName,secondLastName或这些的组合。 例如,我的名字:
姓:毛, 名字:Ubilla, secondLastName:卡瓦哈尔,
如果我搜索“毛Ubilla卡瓦哈尔”,甚至“毛Ubilla”我希望能出现顶部结果列表。 问题是:
1-我应该如何定义这3个字段的索引?我做了以下几点:
@Indexed
class Patient {
...
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
protected String firstName = new String();
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
protected String lastName = new String();
@Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
protected String secondLastName = new String();
...
}
2-我该如何构建查询?我这样做:
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Patient.class).get();
Query luceneQuery = qb.keyword().onFields("firstName", "lastName", "secondLastName").matching(name).createQuery();
但是,这不适合我。它没有抛出任何异常,只是它没有返回任何东西。 即使我只搜索“Mauricio”,它也不会返回任何内容。
但是,如果我更改查询只符合我的姓:如果我搜索
QueryBuilder qb = fullTextSession.getSearchFactory().buildQueryBuilder().forEntity(Patient.class).get();
Query luceneQuery = qb.keyword().onFields("firstName").matching(name).createQuery();
“毛”它的工作原理。
我在做什么错?有什么办法可以为3列定义组合索引吗?我应该以不同的方式构建我的查询吗? 请帮助我顺便说一句:( ,我使用Hibernate Search的4.5.1在休眠4.3和Java 1.7
谢谢获得!这就是我所做的,它工作正常。同时感谢您对升级到更新版本hibernate的建议。好像我很快就要做。 –