3 * Copyright (C) 2011 EDIT
4 * European Distributed Institute of Taxonomy
5 * http://www.e-taxonomy.eu
7 * The contents of this file are subject to the Mozilla Public License Version 1.1
8 * See LICENSE.TXT at the top of this package for the full license terms.
10 package eu
.etaxonomy
.cdm
.hibernate
.search
;
12 import org
.apache
.lucene
.document
.Document
;
13 import org
.apache
.lucene
.document
.Field
;
14 import org
.apache
.lucene
.document
.Field
.Index
;
15 import org
.apache
.lucene
.document
.Field
.Store
;
16 import org
.hibernate
.search
.bridge
.FieldBridge
;
17 import org
.hibernate
.search
.bridge
.LuceneOptions
;
19 import eu
.etaxonomy
.cdm
.model
.description
.TaxonDescription
;
20 import eu
.etaxonomy
.cdm
.model
.description
.TaxonNameDescription
;
21 import eu
.etaxonomy
.cdm
.model
.name
.TaxonNameBase
;
22 import eu
.etaxonomy
.cdm
.model
.taxon
.Taxon
;
23 import eu
.etaxonomy
.cdm
.model
.taxon
.TaxonNode
;
26 * This class bridge is needed to overcome limitations in hibernate search with polymorphism on associations. See:
28 * <li>"Support runtime polymorphism on associations (instead of defining the indexed properties based on the returned type"
29 * (https://hibernate.onjira.com/browse/HSEARCH-438)</li>
30 * <li>https://forum.hibernate.org/search.php?keywords=indexembedded+subclass&terms=all
31 * &author=&sc=1&sf=all&sk=t&sd=d&sr=posts&st=0&ch=300&t=0&submit=Search</li>
33 * DEVELOPER NOTE: the problem is in {@link org.hibernate.search.engine.DocumentBuilderContainedEntity#initializeClass()} which
34 * is not taking subclasses into account, so the <code>taxon</code> field defined in {@link TaxonDescription} is not
35 * registered in the <code>propertiesMetdata</code>
37 * @author Andreas Kohlbecker
41 public class DescriptionBaseClassBridge
extends AbstractClassBridge
{
47 * @see org.hibernate.search.bridge.FieldBridge#set(java.lang.String,
48 * java.lang.Object, org.apache.lucene.document.Document,
49 * org.hibernate.search.bridge.LuceneOptions)
51 public void set(String name
, Object entity
, Document document
, LuceneOptions luceneOptions
) {
53 if (entity
instanceof TaxonDescription
) {
55 Taxon taxon
= ((TaxonDescription
)entity
).getTaxon();
59 idFieldBridge
.set(name
+ "taxon.id", taxon
.getId(), document
, idFieldOptions
);
61 Field titleCachefield
= new Field(name
+ "taxon.titleCache", taxon
.getTitleCache(), Store
.YES
, Index
.ANALYZED
,
62 luceneOptions
.getTermVector());
63 document
.add(titleCachefield
);
65 Field titleCacheSortfield
= new Field(name
+ "taxon.titleCache__sort", taxon
.getTitleCache(), sortFieldOptions
.getStore(), sortFieldOptions
.getIndex(),
66 luceneOptions
.getTermVector());
67 document
.add(titleCacheSortfield
);
69 Field uuidfield
= new Field(name
+ "taxon.uuid", taxon
.getUuid().toString(), Store
.YES
, Index
.ANALYZED
,
70 luceneOptions
.getTermVector());
71 document
.add(uuidfield
);
73 for(TaxonNode node
: taxon
.getTaxonNodes()){
74 if(node
.getClassification() != null){
75 idFieldBridge
.set(name
+ "taxon.taxonNodes.classification.id", node
.getClassification().getId(), document
, idFieldOptions
);
81 if (entity
instanceof TaxonNameDescription
) {
82 TaxonNameBase taxonName
= ((TaxonNameDescription
) entity
).getTaxonName();
83 if (taxonName
!= null) {
84 idFieldBridge
.set(name
+ "taxonName.id", taxonName
.getId(), document
, idFieldOptions
);