在我的项目中,我们使用带有 lucene-analyzers 和 solar 的 hibernate search 4.5。我为我的客户提供一个文本字段。当他们输入短语时,我想查找User
名称中包含给定短语的所有实体。
例如,考虑在数据库中有以下标题的条目列表:
[ Alan Smith, John Cane, Juno Taylor, Tom Caner Junior ]
jun
应该返回Juno Taylor
并且Tom Caner Junior
an
应该返回Alan Smith
,John Cane
并且Tom Caner Junior
@AnalyzerDef(name = "customanalyzer", tokenizer = @TokenizerDef(factory = WhitespaceTokenizerFactory.class), filters = {
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = SnowballPorterFilterFactory.class, params = { @Parameter(name = "language", value = "English") })
})
@Analyzer(definition = "customanalyzer")
public class Student implements Serializable {
@Column(name = "Fname")
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
private String fname;
@Column(name = "Lname")
@Field(index = Index.YES, store = Store.YES, analyze = Analyze.YES)
private String lname;
}
我尝试过通配符搜索,但是
通配符查询不会将分析器应用于匹配项。否则*或的风险?被破坏太高了。
Query luceneQuery = mythQB
.keyword()
.wildcard()
.onFields("fname")
.matching("ju*")
.createQuery();
我怎样才能做到这一点?