1528
|
1 package luan.modules.lucene;
|
|
2
|
|
3 import java.util.Map;
|
|
4 import java.util.Collections;
|
|
5 import org.apache.lucene.index.IndexWriterConfig;
|
|
6 import org.apache.lucene.index.SnapshotDeletionPolicy;
|
|
7 import org.apache.lucene.util.Version;
|
|
8 import goodjava.lucene.queryparser.MultiFieldParser;
|
|
9 import goodjava.lucene.api.MultiFieldParserConfig;
|
|
10 import goodjava.lucene.api.MoreFieldInfo;
|
|
11 import luan.LuanFunction;
|
|
12 import luan.LuanTable;
|
|
13 import luan.LuanCloner;
|
|
14 import luan.LuanException;
|
|
15 import luan.LuanRuntimeException;
|
|
16
|
|
17
|
|
18 final class SupplementingConfig extends MultiFieldParserConfig {
|
|
19 private final LuanFunction supplementer;
|
|
20
|
|
21 SupplementingConfig(Version luceneVersion,MultiFieldParser mfp,LuanFunction supplementer) {
|
|
22 super(luceneVersion,mfp);
|
|
23 LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE);
|
|
24 this.supplementer = (LuanFunction)cloner.get(supplementer);
|
|
25 }
|
|
26
|
|
27 public IndexWriterConfig newLuceneConfig() {
|
|
28 IndexWriterConfig luceneConfig = super.newLuceneConfig();
|
|
29 SnapshotDeletionPolicy snapshotDeletionPolicy = new SnapshotDeletionPolicy(luceneConfig.getIndexDeletionPolicy());
|
|
30 luceneConfig.setIndexDeletionPolicy(snapshotDeletionPolicy);
|
|
31 return luceneConfig;
|
|
32 }
|
|
33
|
|
34 public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) {
|
|
35 if( supplementer == null )
|
|
36 return super.getMoreFieldInfo(storedFields);
|
|
37 try {
|
|
38 LuanTable tbl = LuceneIndex.toTable(supplementer.luan(),storedFields);
|
|
39 tbl = (LuanTable)supplementer.call(tbl);
|
|
40 if( tbl == null ) {
|
|
41 return super.getMoreFieldInfo(storedFields);
|
|
42 } else {
|
|
43 return new MoreFieldInfo(LuceneIndex.toLucene(tbl),Collections.emptyMap());
|
|
44 }
|
|
45 } catch(LuanException e) {
|
|
46 throw new LuanRuntimeException(e);
|
|
47 }
|
|
48 }
|
|
49 }
|