View Javadoc
1   package ca.uhn.fhir.jpa.search;
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.analysis.core.LowerCaseFilterFactory;
24  import org.apache.lucene.analysis.core.StopFilterFactory;
25  import org.apache.lucene.analysis.core.WhitespaceTokenizerFactory;
26  import org.apache.lucene.analysis.miscellaneous.WordDelimiterFilterFactory;
27  import org.apache.lucene.analysis.ngram.EdgeNGramFilterFactory;
28  import org.apache.lucene.analysis.ngram.NGramFilterFactory;
29  import org.apache.lucene.analysis.pattern.PatternTokenizerFactory;
30  import org.apache.lucene.analysis.phonetic.PhoneticFilterFactory;
31  import org.apache.lucene.analysis.snowball.SnowballPorterFilterFactory;
32  import org.apache.lucene.analysis.standard.StandardFilterFactory;
33  import org.apache.lucene.analysis.standard.StandardTokenizerFactory;
34  import org.hibernate.search.annotations.Factory;
35  import org.hibernate.search.cfg.SearchMapping;
36  
37  /**
38   * Factory for defining the analysers.
39   */
40  public class LuceneSearchMappingFactory {
41  	@Factory
42  	public SearchMapping getSearchMapping() {
43  		SearchMapping mapping = new SearchMapping();
44  
45  		mapping.analyzerDef("autocompleteEdgeAnalyzer", PatternTokenizerFactory.class)
46  				.tokenizerParam("pattern", "(.*)")
47  				.tokenizerParam("group", "1")
48  				.filter(LowerCaseFilterFactory.class)
49  				.filter(StopFilterFactory.class)
50  				.filter(EdgeNGramFilterFactory.class)
51  				.param("minGramSize", "3")
52  				.param("maxGramSize", "50")
53  			.analyzerDef("autocompletePhoneticAnalyzer", StandardTokenizerFactory.class)
54  				.filter(StandardFilterFactory.class)
55  				.filter(StopFilterFactory.class)
56  				.filter(PhoneticFilterFactory.class)
57  				.param("encoder", "DoubleMetaphone")
58  				.filter(SnowballPorterFilterFactory.class)
59  				.param("language", "English")
60  			.analyzerDef("autocompleteNGramAnalyzer", StandardTokenizerFactory.class)
61  				.filter(WordDelimiterFilterFactory.class)
62  				.filter(LowerCaseFilterFactory.class)
63  				.filter(NGramFilterFactory.class)
64  				.param("minGramSize", "3")
65  				.param("maxGramSize", "20")
66  			.analyzerDef("standardAnalyzer", StandardTokenizerFactory.class)
67  				.filter(LowerCaseFilterFactory.class)
68  			.analyzerDef("exactAnalyzer", StandardTokenizerFactory.class)
69  			.analyzerDef("conceptParentPidsAnalyzer", WhitespaceTokenizerFactory.class);
70  
71  		return mapping;
72  	}
73  }