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