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.Pathway; 010import org.biopax.paxtools.model.level3.UnificationXref; 011import org.biopax.paxtools.model.level3.Xref; 012import org.hibernate.search.bridge.FieldBridge; 013import org.hibernate.search.bridge.LuceneOptions; 014 015/** 016 * This is a {@link FieldBridge} implementation 017 * for biopax elements to generate a custom search/filter 018 * index field that contain their parent pathway URIs and names. 019 * 020 * @author rodche 021 * @deprecated Hibernate ORM/Search will be removed in v5 022 */ 023public final class ParentPathwayFieldBridge implements FieldBridge { 024 025 @Override 026 public void set(String name, Object value, Document document, LuceneOptions luceneOptions) { 027 if(value instanceof Set) { 028 for(Pathway pw : (Set<Pathway>) value) { 029 //adding URI as is (do not change the URI to lowercase!) 030 FieldBridgeUtils.addFieldToDocumentAsIs(luceneOptions, name, pw.getRDFId(), document); 031 // add names to the index as well 032 for (String s : pw.getName()) { 033 FieldBridgeUtils.addFieldToDocument(luceneOptions, name, s, document); 034 } 035 // add unification xref IDs too 036 for (UnificationXref x : new ClassFilterSet<Xref, UnificationXref>( 037 pw.getXref(), UnificationXref.class)) { 038 if (x.getId() != null) 039 FieldBridgeUtils.addFieldToDocument(luceneOptions, name, x.getId(), document); 040 } 041 } 042 } else { 043 throw new AssertionError("Bug!"); 044 } 045 } 046}