1
|
/**
|
2
|
* Copyright (C) 2012 EDIT
|
3
|
* European Distributed Institute of Taxonomy
|
4
|
* http://www.e-taxonomy.eu
|
5
|
*
|
6
|
* The contents of this file are subject to the Mozilla Public License Version 1.1
|
7
|
* See LICENSE.TXT at the top of this package for the full license terms.
|
8
|
*/
|
9
|
package eu.etaxonomy.cdm.hibernate.search;
|
10
|
|
11
|
import java.util.Collection;
|
12
|
import java.util.Map;
|
13
|
|
14
|
import org.apache.lucene.document.Document;
|
15
|
import org.apache.lucene.document.Field;
|
16
|
import org.apache.lucene.document.TextField;
|
17
|
import org.hibernate.search.bridge.FieldBridge;
|
18
|
import org.hibernate.search.bridge.LuceneOptions;
|
19
|
|
20
|
import eu.etaxonomy.cdm.model.common.Language;
|
21
|
import eu.etaxonomy.cdm.model.common.LanguageString;
|
22
|
|
23
|
/**
|
24
|
* Multilingual text representations, for example in TextData, are modeled in the cdm
|
25
|
* as <code>Map<Language, LanguageString> multilanguageText</code>. This FieldBridge implementation
|
26
|
* stores each of these language specific strings in the Lucene document in two fields, whereas {name}
|
27
|
* is set by the name parameter and will be most probably 'text' or 'multilanguageText':
|
28
|
* <ol>
|
29
|
* <li><code>{name}.ALL</code>: this field contains all strings regardless of the language they are associated with.</li>
|
30
|
* <li></li><code>{name}.{language-label}</code>: contains the strings of the specific language indicated by {language-label}.
|
31
|
* </ol>
|
32
|
*
|
33
|
* @author Andreas Kohlbecker
|
34
|
\* @since Jun 4, 2012
|
35
|
*
|
36
|
*/
|
37
|
public class MultilanguageTextFieldBridge implements FieldBridge {
|
38
|
|
39
|
@Override
|
40
|
public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
|
41
|
// value should be the Map<Language, LanguageString>
|
42
|
@SuppressWarnings("unchecked")
|
43
|
Collection<LanguageString> langStrings = ((Map<Language, LanguageString>)value).values();
|
44
|
for(LanguageString languageString : langStrings){
|
45
|
|
46
|
if(languageString.getText() == null) {
|
47
|
// TextField.value cannot be null
|
48
|
continue;
|
49
|
}
|
50
|
|
51
|
Field allField = new TextField(name + ".ALL",
|
52
|
languageString.getText(),
|
53
|
luceneOptions.getStore());
|
54
|
allField.setBoost(luceneOptions.getBoost());
|
55
|
document.add(allField);
|
56
|
|
57
|
Field langField = new TextField(name + "." + languageString.getLanguage().getUuid(),
|
58
|
languageString.getText(),
|
59
|
luceneOptions.getStore()
|
60
|
);
|
61
|
allField.setBoost(luceneOptions.getBoost());
|
62
|
document.add(langField);
|
63
|
}
|
64
|
|
65
|
}
|
66
|
|
67
|
}
|