简体   繁体   中英

hibernate search multiple fields based on language

I'm interested in changing db full text search to lucene. I'm using hibernate so I guess it would be smart to use hibernate search. I have a problem though.

Our record has a list of informations and titles from different languages and I need to be able to search based on a single language and over all languages.

I could probably do it in plain lucene but I don't know how well it would work with current transactions. So using hibernate search and hibernate to deal with the index would be much better.

Is it possible to create such fields in the index to search the way I described?

class Record{
    List<Info> infos;
}

class Info{
    String title;
    String infoText;
    String langCode;
}

Can I do it like this. Create getters in Record like this:

public String getEnghlishTitle(){...}

public String getFullInfos(){...}

And then put index annotations on these getters and then have necessary fields in index?

I would write a custom FieldBridge for the infos property. Then you have full control which fields you add to the index, eg you could could use text. as field names. This should allow to dynamically decide which language to search for. Remember you have to think about the analyzers too. A custom per field analyzer would work.

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