0

我将休眠搜索 4.2.0 与休眠 4.2.15 和弹簧 3.2.10 一起使用。使用休眠搜索(lucene)查询时,我有一个奇怪的行为。

在数据库中,我为字段内容设置了这个值:“méchant”。当我使用“mechant”进行查询时,它工作正常,我得到了对象。但是当我使用“méchant”时它不起作用......

映射:

@Entity
@Indexed
@AnalyzerDef(name = "customAnalyzer",
    tokenizer = @TokenizerDef(factory = StandardTokenizerFactory.class),
    filters = {
        @TokenFilterDef(factory = LowerCaseFilterFactory.class),
        @TokenFilterDef(factory = ASCIIFoldingFilterFactory.class),
        @TokenFilterDef(factory = SnowballPorterFilterFactory.class)
    })
@Table(name = "MESSAGE")
public class Message {

    ...

    @Id
    @DocumentId
    @GeneratedValue
    @Column(name = "ID_MESSAGE")
    public Integer getId() {
        return id;
    }

    @Field(index=Index.YES, analyze=Analyze.YES, store=Store.NO)
    @Analyzer(definition="customAnalyzer")
    @Column(name = "CONTENT", length = 65535, columnDefinition = "Text")
    public String getContent() {
        return content;
    }

    ...
]

休眠配置:

<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean" >
    <property name="dataSource" ref="customDataSource" />
    <property name="hibernateProperties">
        <props>
        <prop key="hibernate.bytecode.provider">javassist</prop>
        <prop key="hibernate.dialect">org.hibernate.dialect.MySQLDialect</prop>
        <prop key="hibernate.show_sql">${hibernate.showSql}</prop>
        <prop key="hibernate.hbm2ddl.auto">validate</prop>
        <prop key="hibernate.search.default.directory_provider">filesystem</prop>

        <prop key="hibernate.search.default.indexBase">${indexLucene.path}</prop>
        </props>
    </property>
</bean>    

查询:

FullTextSession searchSession = Search.getFullTextSession(getSessionFactory().getCurrentSession());
QueryBuilder qb = searchSession.getSearchFactory().buildQueryBuilder().forEntity(Message.class).get();
BooleanJunction<BooleanJunction> bool = qb.bool();

...

bool.must(qb.keyword().boostedTo(4f)
    .onFields("content")
    .matching(messageCriteria.getQuery())
    .createQuery());
...

org.apache.lucene.search.Query luceneQuery =bool.createQuery(); 
FullTextQuery jpaQuery = searchSession.createFullTextQuery(luceneQuery, Message.class);

有人可以帮助我吗?

[编辑] 谢谢大家,我解决了这个问题:这不是由于休眠搜索,而是我的 http 请求的字符集。我将检查如何解决我的字符集问题。对不起,浪费时间...

4

1 回答 1

0

在您的示例中,您只是在SnowballPorterFilterFactory没有指定语言参数的情况下使用。这默认为英语,这可能不是您想要的。您是否尝试将其更改为您的目标语言?

于 2014-11-03T18:58:30.080 回答