0
@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来索引具有多个单词的短语。另一个使用StandardTokenizerFactoryShingleFilterFactory将在查询时使用,但是我无法从我的搜索查询中接收令牌组合。我所期待的是:当搜索查询是我的搜索查询时,它应该是我的搜索搜索查询,但我得到的是搜索查询

下面是我的功能

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 AWord B并且我正在搜索单词 a 的位置(以便它显示Word A 的记录)但没有结果。这是因为在搜索查询包含被索引的短语之前,我不想显示任何结果。

4

2 回答 2

0

没有任何人的回答导致我自己深入研究问题并自己找到了答案。因为它可能对其他人有帮助,所以我在这里写它并且解决方案非常简单,只需将 searchQuery 包含在引号中。

于 2012-05-14T06:45:57.830 回答
0

我使用了:

@TokenizerDef(factory = StandardTokenizerFactory.class),

在您的标签分析器中,您的代码运行良好。

现在我想知道为什么您使用不同的标记器一个用于查询而另一个用于存储?

于 2014-05-27T13:44:49.093 回答