简体   繁体   中英

Hibernate Search facet returns values in lowercase

I'm a newbie to Hibernate Search facets. I'm using facets and I notice you can only return the value of the fieldName

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 ?

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? Or is it recommended to store the value in the index in it's original format and do a getFacetQuery to get it? I don't know anything about the getFacetQuery , so this might not be possible.

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;
    }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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