Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/java/324.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Java 带重音的hibernate搜索查询_Java_Lucene_Hibernate Search_Accent Insensitive - Fatal编程技术网

Java 带重音的hibernate搜索查询

Java 带重音的hibernate搜索查询,java,lucene,hibernate-search,accent-insensitive,Java,Lucene,Hibernate Search,Accent Insensitive,我将HibernateSearch4.2.0与Hibernate4.2.15和Spring3.2.10结合使用。 当使用hibernate搜索(lucene)查询时,我有一个奇怪的行为 在数据库中,我为字段内容设置了这个值:“méchant”。 当我用“mechant”进行查询时,它工作正常,我得到了objet。 但当我用“唱梅尚”时,它不起作用 映射: @Entity @Indexed @AnalyzerDef(name = "customAnalyzer", tokenizer =

我将HibernateSearch4.2.0与Hibernate4.2.15和Spring3.2.10结合使用。 当使用hibernate搜索(lucene)查询时,我有一个奇怪的行为

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

映射:

@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>    

javassist
org.hibernate.dialogue.mysqldialogue
${hibernate.showSql}
验证
文件系统
${indexLucene.path}
查询:

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);
FullTextSession Search session=Search.getFullTextSession(getSessionFactory().getCurrentSession());
QueryBuilder qb=searchSession.getSearchFactory().buildQueryBuilder().forEntity(Message.class.get();
BooleanJunction bool=qb.bool();
...
bool.must(qb.keyword().boostedTo(4f)
.onFields(“内容”)
.matching(messageCriteria.getQuery())
.createQuery());
...
org.apache.lucene.search.Query luceneQuery=bool.createQuery();
FullTextQuery jpaQuery=searchSession.createFullTextQuery(luceneQuery,Message.class);
有人能帮我吗

[编辑]谢谢大家,我解决了这个问题:这不是因为hibernate搜索,而是我http请求的字符集。我将检查如何修复我的字符集问题。
很抱歉浪费时间…

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

很明显,您在查询时使用了错误的分析器。我真的不太清楚Hibernate在查询时是如何处理分析器的,所以这里就简单介绍一下,但是如果您将
onFields(“content”)
更改为
onField(“content”)
,会发生什么呢?如果我使用
onField(“content”)
,则没有任何变化:
@TokenFilterDef(factory=SnowballPorterFilterFactory.class,params=@Parameter(name=“language”,value=“French”)
没有效果。。。