001/**
002 * 
003 */
004package org.biopax.paxtools.util;
005
006import java.util.Set;
007
008import org.apache.lucene.document.Document;
009import org.biopax.paxtools.model.level3.XReferrable;
010import org.biopax.paxtools.model.level3.Xref;
011import org.hibernate.search.bridge.FieldBridge;
012import org.hibernate.search.bridge.LuceneOptions;
013
014/**
015 * This Hibernate search field bridge implementation is to be applied 
016 * to the 'xref' object properties of many biopax {@link XReferrable} classes, 
017 * such as EntityReference, Protein, etc., and allows finding these objects 
018 * by some identifier (e.g., UniProt, HGNC Symbol, etc.). Without this bridge, 
019 * one could only find an instance of {@link Xref} by 'id' or URI.
020 * 
021 * @author rodche
022 * @deprecated Hibernate ORM/Search will be removed in v5
023 */
024public final class XrefFieldBridge implements FieldBridge {
025
026        @Override
027        public void set(String name, Object value, Document document, LuceneOptions luceneOptions) {
028                if (value instanceof Set) { //is getXref() values
029                        Set<Xref> refs = (Set<Xref>) value;
030                        for (Xref x : refs) {
031                                if (x.getId() != null)
032                                        FieldBridgeUtils.addFieldToDocument(luceneOptions, name,
033                                                        x.getId(), document); //note: this actually saves value.toLowercase
034                        }
035                }
036        }
037        
038}