View Javadoc
1   /*
2    * Copyright 2010 James Pether Sörling
3    *
4    * Licensed under the Apache License, Version 2.0 (the "License");
5    * you may not use this file except in compliance with the License.
6    * You may obtain a copy of the License at
7    *
8    *   http://www.apache.org/licenses/LICENSE-2.0
9    *
10   * Unless required by applicable law or agreed to in writing, software
11   * distributed under the License is distributed on an "AS IS" BASIS,
12   * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13   * See the License for the specific language governing permissions and
14   * limitations under the License.
15   *
16   *	$Id$
17   *  $HeadURL$
18  */
19  package com.hack23.cia.service.data.impl;
20  
21  import java.lang.annotation.ElementType;
22  
23  import org.apache.lucene.analysis.core.LowerCaseFilterFactory;
24  import org.apache.lucene.analysis.en.PorterStemFilterFactory;
25  import org.apache.lucene.analysis.ngram.NGramFilterFactory;
26  import org.apache.lucene.analysis.standard.StandardTokenizerFactory;
27  import org.apache.lucene.analysis.sv.SwedishLightStemFilterFactory;
28  import org.hibernate.search.annotations.Analyze;
29  import org.hibernate.search.annotations.Factory;
30  import org.hibernate.search.annotations.Store;
31  import org.hibernate.search.cfg.SearchMapping;
32  
33  import com.hack23.cia.model.external.riksdagen.documentcontent.impl.DocumentContentData;
34  import com.hack23.cia.model.external.riksdagen.dokumentlista.impl.DocumentElement;
35  import com.hack23.cia.model.external.riksdagen.dokumentstatus.impl.DocumentStatusContainer;
36  
37  /**
38   * A factory for creating DataSearchMapping objects.
39   */
40  public final class DataSearchMappingFactory {
41  
42  	/**
43  	 * Gets the search mapping.
44  	 *
45  	 * @return the search mapping
46  	 */
47  	@Factory
48  	public SearchMapping getSearchMapping() {
49  		final SearchMapping mapping = new SearchMapping();
50  		mapping.analyzerDef("ngram", StandardTokenizerFactory.class).filter(LowerCaseFilterFactory.class)
51  				.filter(NGramFilterFactory.class).param("minGramSize", "3").param("maxGramSize", "3")
52  				.analyzerDef("se", StandardTokenizerFactory.class).filter(LowerCaseFilterFactory.class)
53  				.filter(SwedishLightStemFilterFactory.class).analyzerDef("en", StandardTokenizerFactory.class)
54  				.filter(LowerCaseFilterFactory.class).filter(PorterStemFilterFactory.class)
55  				.entity(DocumentContentData.class).indexed().property("hjid", ElementType.FIELD).documentId().property("content", ElementType.METHOD).field().analyzer("se").store(Store.NO).analyze(Analyze.YES).property("id", ElementType.METHOD).field()
56  				.entity(DocumentElement.class).indexed().property("id", ElementType.FIELD).documentId().property("title", ElementType.METHOD).field().analyzer("se").store(Store.NO).analyze(Analyze.YES).property("subTitle", ElementType.METHOD).field().analyzer("se").store(Store.NO).analyze(Analyze.YES)
57  				.entity(DocumentStatusContainer.class).indexed().property("hjid", ElementType.FIELD).documentId().property("documentCategory", ElementType.METHOD).field().analyzer("se").store(Store.NO).analyze(Analyze.YES);
58  
59  		return mapping;
60  	}
61  }