@AnalyzerDef(
name = "tags",
tokenizer =
@TokenizerDef(factory = PatternTokenizerFactory.class,
params = {
@Parameter(name = "pattern", value=",")
}
),
filters = {
@TokenFilterDef(factory = StandardFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(
factory = StopFilterFactory.class,
params = {
@Parameter(name = "words", value = "data/ignorewords.txt"),
@Parameter(name = "ignoreCase", value = "true")
}
),
@TokenFilterDef(
factory = SynonymFilterFactory.class,
params = {
@Parameter(name = "ignoreCase", value="true"),
@Parameter(name = "expand", value="false"),
@Parameter(name = "synonyms", value="data/synonyms.txt")
}
),
@TokenFilterDef(
factory = SnowballPorterFilterFactory.class,
params = {
@Parameter(name = "language", value="English")
}
),
@TokenFilterDef(
factory = ShingleFilterFactory.class,
params = {
@Parameter(name = "minShingleSize", value="2"),
@Parameter(name = "maxShingleSize", value="3"),
@Parameter(name = "outputUnigrams", value="true"),
@Parameter(name = "outputUnigramsIfNoShingles", value="false")
}
),
@TokenFilterDef(
factory = PositionFilterFactory.class,
params = {
@Parameter(name = "positionIncrement", value = "100")
}
),
@TokenFilterDef(
factory = PhoneticFilterFactory.class,
params = {
@Parameter(name = "encoder", value="RefinedSoundex"),
@Parameter(name = "inject", value="true")
}
)
}
),
@AnalyzerDef(
name = "querytime",
tokenizer =
@TokenizerDef(factory = StandardTokenizerFactory.class),
filters = {
@TokenFilterDef(factory = StandardFilterFactory.class),
@TokenFilterDef(factory = LowerCaseFilterFactory.class),
@TokenFilterDef(factory = StopFilterFactory.class,
params = {
@Parameter(name = "words", value = "data/ignorewords.txt"),
@Parameter(name = "ignoreCase", value = "true")
}
),
@TokenFilterDef(
factory = SnowballPorterFilterFactory.class,
params = {
@Parameter(name = "language", value="English")
}
),
@TokenFilterDef(
factory = ShingleFilterFactory.class,
params = {
@Parameter(name = "minShingleSize", value="2"),
@Parameter(name = "maxShingleSize", value="3"),
@Parameter(name = "outputUnigrams", value="true"),
@Parameter(name = "outputUnigramsIfNoShingles", value="false")
}
),
@TokenFilterDef(
factory = PositionFilterFactory.class,
params = {
@Parameter(name = "positionIncrement", value = "100")
}
),
@TokenFilterDef(
factory = PhoneticFilterFactory.class,
params = {
@Parameter(name = "encoder", value="RefinedSoundex"),
@Parameter(name = "inject", value="true")
}
)
}
)
})
以上是我的分析器定义,我在索引时使用PatternTokenizerFactory来索引具有多个单词的短语。另一个使用StandardTokenizerFactory和ShingleFilterFactory将在查询时使用,但是我无法从我的搜索查询中接收令牌组合。我所期待的是:当搜索查询是我的搜索查询时,它应该是我的搜索和搜索查询,但我得到的是我的搜索和查询
下面是我的功能
FullTextSession fullTextSession = Search.getFullTextSession(session);
Transaction tx = fullTextSession.beginTransaction();
// create native Lucene query
org.apache.lucene.search.Query luceneQuery = null;
String[] fields = new String[] {"tags"};
MultiFieldQueryParser parser = new MultiFieldQueryParser(
Version.LUCENE_31, fields, fullTextSession.getSearchFactory().getAnalyzer("querytime"));
try {
luceneQuery = parser.parse(searchQuery);
} catch (ParseException e) {
e.printStackTrace();
}
// wrap Lucene query in a org.hibernate.Query
org.hibernate.Query hibQuery = fullTextSession.createFullTextQuery(luceneQuery, CityArea.class);
// execute search
List result = hibQuery.list();
tx.commit();
session.close();
return result;
问题是我的索引标记是 ex:说Word A,Word B并且我正在搜索单词 a 的位置(以便它显示Word A 的记录)但没有结果。这是因为在搜索查询包含被索引的短语之前,我不想显示任何结果。