我有两个用户名为' Alex'和安德烈'。当我写出像A'这样的查询时,我得到0结果。我必须使用全名和匹配的大写字母进行搜索才能得到结果。
我想要例如只查询' e'最终获得2条记录。
Session s = session.getCurrentSession();
FullTextSession fullTextSession = Search.getFullTextSession(s);
QueryBuilder qb = fullTextSession.getSearchFactory()
.buildQueryBuilder().forEntity(User.class).get();
org.apache.lucene.search.Query q = qb
.keyword().onFields("name")
.matching(query)
.createQuery();
org.hibernate.Query hibQuery =
fullTextSession.createFullTextQuery(q, User.class);
List<User> results = hibQuery.list();
答案 0 :(得分:0)
您没有展示如何索引名字。这也很重要。例如,如果您将索引存储为未分析的,则需要考虑大写。同样如comment中所述,您需要查看正确的分析器。只有在使用通配符查询时才能使用该案例。
在切线上,我不知道您的示例与您的实际用例有多接近,但搜索单个字符可能不是典型的自由文本搜索用例。
答案 1 :(得分:0)
这种特殊的行为让我想起了我曾经遇到的一个错误。
'A'是Hibernate Search标准分析器使用的停用词(英语),因此您必须精确定制没有此停用词的自定义分析器。
这些链接可以帮助您
使用自定义分析器:https://docs.jboss.org/hibernate/search/3.1/reference/en/html/search-mapping.html
要明白我对'a'的意思,就像一个停用词:Getting error on a specific query