1
|
/**
|
2
|
* Copyright (C) 2011 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 org.apache.lucene.document.Document;
|
12
|
import org.apache.lucene.document.Field;
|
13
|
import org.apache.lucene.document.Field.Store;
|
14
|
import org.apache.lucene.document.StringField;
|
15
|
import org.apache.lucene.document.TextField;
|
16
|
import org.hibernate.search.bridge.LuceneOptions;
|
17
|
|
18
|
import eu.etaxonomy.cdm.model.description.TaxonDescription;
|
19
|
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
|
20
|
import eu.etaxonomy.cdm.model.name.TaxonName;
|
21
|
import eu.etaxonomy.cdm.model.taxon.Taxon;
|
22
|
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
|
23
|
|
24
|
/**
|
25
|
* This class bridge is needed to overcome limitations in hibernate search with polymorphism on associations. See:
|
26
|
* <ol>
|
27
|
* <li>"Support runtime polymorphism on associations (instead of defining the indexed properties based on the returned type"
|
28
|
* (https://hibernate.onjira.com/browse/HSEARCH-438)</li>
|
29
|
* <li>https://forum.hibernate.org/search.php?keywords=indexembedded+subclass&terms=all
|
30
|
* &author=&sc=1&sf=all&sk=t&sd=d&sr=posts&st=0&ch=300&t=0&submit=Search</li>
|
31
|
*</ol>
|
32
|
* DEVELOPER NOTE: the problem is in {@link org.hibernate.search.engine.DocumentBuilderContainedEntity#initializeClass()} which
|
33
|
* is not taking subclasses into account, so the <code>taxon</code> field defined in {@link TaxonDescription} is not
|
34
|
* registered in the <code>propertiesMetdata</code>
|
35
|
*
|
36
|
* @author Andreas Kohlbecker
|
37
|
* @since Dec 19, 2011
|
38
|
*
|
39
|
*/
|
40
|
public class DescriptionBaseClassBridge extends AbstractClassBridge {
|
41
|
|
42
|
@Override
|
43
|
public void set(String name, Object entity, Document document, LuceneOptions luceneOptions) {
|
44
|
|
45
|
if (entity instanceof TaxonDescription) {
|
46
|
|
47
|
Taxon taxon = ((TaxonDescription)entity).getTaxon();
|
48
|
|
49
|
if (taxon != null) {
|
50
|
|
51
|
idFieldBridge.set(name + "taxon.id", taxon.getId(), document, idFieldOptions);
|
52
|
|
53
|
Field titleCachefield = new TextField(name + "taxon.titleCache", taxon.getTitleCache(), Store.YES);
|
54
|
document.add(titleCachefield);
|
55
|
|
56
|
// this should not be necessary since the IdentifiableEntity.titleCache already has the according annotation
|
57
|
/*
|
58
|
Field titleCacheSortfield = new SortedDocValuesField(
|
59
|
name + "taxon.titleCache__sort",
|
60
|
new BytesRef(taxon.getTitleCache())
|
61
|
);
|
62
|
LuceneDocumentUtility.setOrReplaceDocValueField(titleCacheSortfield, document);
|
63
|
*/
|
64
|
|
65
|
Field uuidfield = new StringField(name + "taxon.uuid", taxon.getUuid().toString(), Store.YES);
|
66
|
document.add(uuidfield);
|
67
|
|
68
|
for(TaxonNode node : taxon.getTaxonNodes()){
|
69
|
if(node.getClassification() != null){
|
70
|
idFieldBridge.set(name + "taxon.taxonNodes.classification.id",
|
71
|
node.getClassification().getId(), document, idFieldOptions);
|
72
|
}
|
73
|
if(node.treeIndex() != null){
|
74
|
Field treeIndexField = new StringField("inDescription.taxon.taxonNodes.treeIndex",
|
75
|
node.treeIndex(),
|
76
|
Store.YES
|
77
|
);
|
78
|
document.add(treeIndexField);
|
79
|
}
|
80
|
}
|
81
|
}
|
82
|
|
83
|
}
|
84
|
if (entity instanceof TaxonNameDescription) {
|
85
|
TaxonName taxonName = ((TaxonNameDescription) entity).getTaxonName();
|
86
|
if (taxonName != null) {
|
87
|
idFieldBridge.set(name + "taxonName.id", taxonName.getId(), document, idFieldOptions);
|
88
|
}
|
89
|
}
|
90
|
}
|
91
|
|
92
|
|
93
|
}
|