如何在Hibernate Search中搜索两个词并同时获得两个词? [英] How can I search for two terms in Hibernate Search and get them both in result?
问题描述
在Hibernate Search中是否可以找到包含所有搜索词的结果?我的意思是,例如,我搜索给定的术语,例如"house",然后获得"Houses"列表.但是,如果我想细化搜索范围并查找"house"和"pool",我想获取"house"和"pool"的列表,而不是"house"或"pool"的列表. 我不确定我是否足够清楚.因此,基本上,我需要用一个以上的单词进行搜索,并且搜索必须考虑所有单词,而不仅仅是一个单词. 那可能吗? 谢谢
Is there some way to find results in Hibernate Search with all searched terms ? What I mean is that, for instance, I search for a given term like "house" and I got a list of "Houses". However, if I'd want go refine my search and look for "house" and "pool", I'd like to get a list of "house" AND "pool" and not a list of "house" OR "pool". I'm not sure I'm clear enough. So, basically, what I need is to perform a search with more than one word and the search must consider them all, not only one. Is that possible? Thanks
推荐答案
您可以使用QueryParser将默认运算符设置为AND:
you can set default operator to AND using QueryParser:
QueryParser queryParser = new QueryParser(Version.LUCENE_36, "yourfield",standardAnalyzer);
// query terms should ANDed by default
queryParser.setDefaultOperator(Operator.AND);
Query luceneQuery = queryParser.parse("house pool");
// turn it into an hibernate search query
org.hibernate.search.FullTextQuery hibQuery =
session.createFullTextQuery(luceneQuery, YourClass.class);
这篇关于如何在Hibernate Search中搜索两个词并同时获得两个词?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!