1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
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
39
40 public final class DataSearchMappingFactory {
41
42
43
44
45
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 }