简体   繁体   English

Hibernate Search构面以小写形式返回值

[英]Hibernate Search facet returns values in lowercase

I'm a newbie to Hibernate Search facets. 我是Hibernate Search方面的新手。 I'm using facets and I notice you can only return the value of the fieldName 我使用的是构面,我注意到您只能返回fieldNamevalue

http://docs.jboss.org/hibernate/search/4.2/api/ http://docs.jboss.org/hibernate/search/4.2/api/

The problem I'm having has to do with my standard analyzer indexing my values in lowercase. 我所遇到的问题与我的标准分析器将我的值索引为小写有关。 So far everything is good until I need to display the data. 到目前为止,一切都很好,直到我需要显示数据为止。

How do I return the value from the facet in it's original case, example Ford , Chevrolet etc rather than ford , chevrolet ? 在原始情况下,如何从方面返回值,例如FordChevrolet等,而不是fordchevrolet

Is there an efficient way to get the value from the database by returning the pk from the value and build an actual object from the database? 是否有一种有效的方法,可以通过从值返回pk并从数据库构建实际对象来从数据库获取值? Or is it recommended to store the value in the index in it's original format and do a getFacetQuery to get it? 还是建议以原始格式将值存储在索引中,并执行getFacetQuery来获取它? I don't know anything about the getFacetQuery , so this might not be possible. 我对getFacetQuery一无所知 ,所以这可能是不可能的。

example

@Entity
public class Make {

@Field(store = Store.no)
private String name

}

values

database: Chevy|Ford
index: chevy|ford

facet

public FacetingRequest getMakeFacetRequest(QueryBuilder builder) {
    return builder.facet()
        .name("make")
        .onField("make.name")
        .discrete()
        .orderedBy(FacetSortOrder.FIELD_VALUE)
        .includeZeroCounts(false)
        .maxFacetCount(10)
        .createFacetingRequest();
 }

Results 结果

chevy|ford

However I'd like the original case from the database. 但是我想要数据库中的原始案例。

Please recommend a best practice. 请推荐最佳做法。 Thank you. 谢谢。

It looks like the solution to my issue was to provide another field to my index that was not analyzed. 看来,解决我的问题的方法是为索引提供另一个未分析的字段。 Example

Entity 实体

private class Make {
@Fields({
        @Field(name = "name", analyzer = @Analyzer(definition = "searchtokenanalyzer")),
        @Field(name = "label", analyze = Analyze.NO)
    })
    private String name;
}

Facet Query 方面查询

@Override
    public FacetingRequest getMakeFacetRequest(QueryBuilder builder) {
        FacetingRequest facetingRequest = builder.facet()
                .name("make")
                .onField("make.label")
                .discrete()
                .orderedBy(FacetSortOrder.FIELD_VALUE)
                .includeZeroCounts(true)
                .maxFacetCount(10)
                .createFacetingRequest();
        return facetingRequest;
    }

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM