如何使用休眠搜索获得部分匹配和完全匹配
How to get partial match as well as full match using hibernate search
FullTextEntityManager fullTextEntityManager =Search.getFullTextEntityManager(emanager);
QueryBuilder qb=fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get();
Query statusNotArchieved = qb.keyword().onField("name").matching("John Cena").createQuery();
Now i Should get Results where result should contain person name
containing John Cena as well as any phrase that contains either John
Or Cena Separately. So if there are three rows for the Person name
containing {"John Cena","John micheal","Micheal Cena"} i want all the
results prioritizing John Cena as first Result
您提供的查询应该与您描述的完全一样:任何包含 "John" 或 "Cena" 的文档都将被匹配,同时匹配的文档将获得更高的分数,因此出现在靠近顶部的位置结果。
也就是说,假设您启用了对字段 "name" 的分析,这是默认情况。
如果您遇到不同的行为,请提供更多信息:
- 您的
Person
实体的完整代码
- 用于构建查询的完整代码(您只给出了开头。
- 您获得的结果的简短描述:文档、它们的顺序和它们 "name" 字段的内容。
FullTextEntityManager fullTextEntityManager =Search.getFullTextEntityManager(emanager);
QueryBuilder qb=fullTextEntityManager.getSearchFactory().buildQueryBuilder().forEntity(Person.class).get();
Query statusNotArchieved = qb.keyword().onField("name").matching("John Cena").createQuery();
Now i Should get Results where result should contain person name containing John Cena as well as any phrase that contains either John Or Cena Separately. So if there are three rows for the Person name containing {"John Cena","John micheal","Micheal Cena"} i want all the results prioritizing John Cena as first Result
您提供的查询应该与您描述的完全一样:任何包含 "John" 或 "Cena" 的文档都将被匹配,同时匹配的文档将获得更高的分数,因此出现在靠近顶部的位置结果。
也就是说,假设您启用了对字段 "name" 的分析,这是默认情况。
如果您遇到不同的行为,请提供更多信息:
- 您的
Person
实体的完整代码 - 用于构建查询的完整代码(您只给出了开头。
- 您获得的结果的简短描述:文档、它们的顺序和它们 "name" 字段的内容。