简体   繁体   中英

Hibernate Search Facet on multiple fields

Let's assume a have an index with multiple fields created from @Indexed entities:

----------------------------------
| FieldA | FiedlB | FieldC | ... |
----------------------------------
|     AX |     BX | other  | ... |
----------------------------------
|     AZ |     BZ | value  | ... |
----------------------------------

Would it be possible to construct a facet aggregating values from two fields?

For example - A_&_B:

  • AX
  • AZ
  • BX
  • BZ

Any other options possible?

I think your best bet is to define a method aggregating the values of both fields and annotate this method to index it as a facet.

Something like:

@Field(bridge = @FieldBridge(impl = CollectionOfStringsFieldBridge.class), analyze = Analyze.NO)
@Facet
public List<String> getAggregatedField() {
     return yourAggregatedValue;
}

With CollectionOfStringsFieldBridge being something like: https://github.com/hibernate/hibernate-search/blob/master/orm/src/test/java/org/hibernate/search/test/embedded/fieldoncollection/CollectionOfStringsFieldBridge.java

It's better than aggregating the facet values returned by Lucene manually.

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