-// $Id$
/**
* Copyright (C) 2011 EDIT
* European Distributed Institute of Taxonomy
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
-import org.apache.lucene.document.Field.Index;
import org.apache.lucene.document.Field.Store;
-import org.hibernate.search.bridge.FieldBridge;
+import org.apache.lucene.document.StringField;
+import org.apache.lucene.document.TextField;
import org.hibernate.search.bridge.LuceneOptions;
-import eu.etaxonomy.cdm.model.description.DescriptionBase;
-import eu.etaxonomy.cdm.model.description.DescriptionElementBase;
import eu.etaxonomy.cdm.model.description.TaxonDescription;
import eu.etaxonomy.cdm.model.description.TaxonNameDescription;
-import eu.etaxonomy.cdm.model.name.TaxonNameBase;
+import eu.etaxonomy.cdm.model.name.TaxonName;
import eu.etaxonomy.cdm.model.taxon.Taxon;
import eu.etaxonomy.cdm.model.taxon.TaxonNode;
* &author=&sc=1&sf=all&sk=t&sd=d&sr=posts&st=0&ch=300&t=0&submit=Search</li>
*</ol>
* DEVELOPER NOTE: the problem is in {@link org.hibernate.search.engine.DocumentBuilderContainedEntity#initializeClass()} which
- * is not taking subclasses into account, so the <code>taxon</code> field defined in {@link TaxonDescription} is not registered in the <code>propertiesMetdata</code>
+ * is not taking subclasses into account, so the <code>taxon</code> field defined in {@link TaxonDescription} is not
+ * registered in the <code>propertiesMetdata</code>
*
* @author Andreas Kohlbecker
- * @date Dec 19, 2011
+ * @since Dec 19, 2011
*
*/
-public class DescriptionBaseClassBridge implements FieldBridge {
+public class DescriptionBaseClassBridge extends AbstractClassBridge {
- /*
- * (non-Javadoc)
- *
- * @see org.hibernate.search.bridge.FieldBridge#set(java.lang.String,
- * java.lang.Object, org.apache.lucene.document.Document,
- * org.hibernate.search.bridge.LuceneOptions)
- */
+ @Override
public void set(String name, Object entity, Document document, LuceneOptions luceneOptions) {
+
if (entity instanceof TaxonDescription) {
- Taxon taxon = ((TaxonDescription) entity).getTaxon();
+
+ Taxon taxon = ((TaxonDescription)entity).getTaxon();
+
if (taxon != null) {
- Field idfield = new Field(name + "taxon.id", String.valueOf(taxon.getId()), Store.YES, Index.ANALYZED,
- luceneOptions.getTermVector());
- document.add(idfield);
- Field titleCachefield = new Field(name + "taxon.titleCache", taxon.getTitleCache(), Store.YES, Index.ANALYZED,
- luceneOptions.getTermVector());
+
+ idFieldBridge.set(name + "taxon.id", taxon.getId(), document, idFieldOptions);
+
+ Field titleCachefield = new TextField(name + "taxon.titleCache", taxon.getTitleCache(), Store.YES);
document.add(titleCachefield);
- Field titleCacheSortfield = new Field(name + "taxon.titleCache__sort", taxon.getTitleCache(), Store.YES, Index.NOT_ANALYZED,
- luceneOptions.getTermVector());
- document.add(titleCacheSortfield);
- Field uuidfield = new Field(name + "taxon.uuid", taxon.getUuid().toString(), Store.YES, Index.ANALYZED,
- luceneOptions.getTermVector());
+
+ // this should not be necessary since the IdentifiableEntity.titleCache already has the according annotation
+ /*
+ Field titleCacheSortfield = new SortedDocValuesField(
+ name + "taxon.titleCache__sort",
+ new BytesRef(taxon.getTitleCache())
+ );
+ LuceneDocumentUtility.setOrReplaceDocValueField(titleCacheSortfield, document);
+ */
+
+ Field uuidfield = new StringField(name + "taxon.uuid", taxon.getUuid().toString(), Store.YES);
document.add(uuidfield);
+
for(TaxonNode node : taxon.getTaxonNodes()){
if(node.getClassification() != null){
- Field taxonNodeField = new Field(name + "taxon.taxonNodes.classification.id", String.valueOf(node.getClassification().getId()), Store.YES, Index.ANALYZED,
- luceneOptions.getTermVector());
- document.add(taxonNodeField);
+ idFieldBridge.set(name + "taxon.taxonNodes.classification.id",
+ node.getClassification().getId(), document, idFieldOptions);
+ }
+ if(node.treeIndex() != null){
+ Field treeIndexField = new StringField("inDescription.taxon.taxonNodes.treeIndex",
+ node.treeIndex(),
+ Store.YES
+ );
+ document.add(treeIndexField);
}
}
}
}
if (entity instanceof TaxonNameDescription) {
- TaxonNameBase taxonName = ((TaxonNameDescription) entity).getTaxonName();
+ TaxonName taxonName = ((TaxonNameDescription) entity).getTaxonName();
if (taxonName != null) {
- Field field = new Field(name + "taxonName.id", String.valueOf(taxonName.getId()), luceneOptions.getStore(), luceneOptions.getIndex(),
- luceneOptions.getTermVector());
- document.add(field);
+ idFieldBridge.set(name + "taxonName.id", taxonName.getId(), document, idFieldOptions);
}
}
}
+
}