View Javadoc
1   package ca.uhn.fhir.jpa.entity;
2   
3   /*-
4    * #%L
5    * HAPI FHIR JPA Server
6    * %%
7    * Copyright (C) 2014 - 2018 University Health Network
8    * %%
9    * Licensed under the Apache License, Version 2.0 (the "License");
10   * you may not use this file except in compliance with the License.
11   * You may obtain a copy of the License at
12   * 
13   *      http://www.apache.org/licenses/LICENSE-2.0
14   * 
15   * Unless required by applicable law or agreed to in writing, software
16   * distributed under the License is distributed on an "AS IS" BASIS,
17   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18   * See the License for the specific language governing permissions and
19   * limitations under the License.
20   * #L%
21   */
22  
23  import org.apache.lucene.document.Document;
24  import org.hibernate.search.bridge.FieldBridge;
25  import org.hibernate.search.bridge.LuceneOptions;
26  import org.hibernate.search.bridge.StringBridge;
27  
28  import java.util.Collection;
29  
30  /**
31   * Allows hibernate search to index individual concepts' properties
32   */
33  public class TermConceptPropertyFieldBridge implements FieldBridge, StringBridge {
34  
35  	public static final String PROP_PREFIX = "PROP__";
36  
37  	/**
38  	 * Constructor
39  	 */
40  	public TermConceptPropertyFieldBridge() {
41  		super();
42  	}
43  
44  	@Override
45  	public String objectToString(Object theObject) {
46  		return theObject.toString();
47  	}
48  
49  	@Override
50  	public void set(String theName, Object theValue, Document theDocument, LuceneOptions theLuceneOptions) {
51  		Collection<TermConceptProperty> properties = (Collection<TermConceptProperty>) theValue;
52  		if (properties != null) {
53  			for (TermConceptProperty next : properties) {
54  				String propValue = next.getKey() + "=" + next.getValue();
55  				theLuceneOptions.addFieldToDocument(theName, propValue, theDocument);
56  
57  				if (next.getType() == TermConceptPropertyTypeEnum.CODING) {
58  					propValue = next.getKey() + "=" + next.getDisplay();
59  					theLuceneOptions.addFieldToDocument(theName, propValue, theDocument);
60  				}
61  			}
62  		}
63  	}
64  }