Mercurial Hosting > luan
annotate src/luan/modules/lucene/SupplementingConfig.java @ 1685:46cf5137cb6b
misc fixes
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Wed, 08 Jun 2022 20:13:54 -0600 |
parents | c922446f53aa |
children | c62324841dfb |
rev | line source |
---|---|
1528 | 1 package luan.modules.lucene; |
2 | |
3 import java.util.Map; | |
1529 | 4 import java.util.LinkedHashMap; |
5 import java.util.List; | |
1528 | 6 import java.util.Collections; |
7 import org.apache.lucene.index.IndexWriterConfig; | |
8 import org.apache.lucene.index.SnapshotDeletionPolicy; | |
9 import org.apache.lucene.util.Version; | |
10 import goodjava.lucene.queryparser.MultiFieldParser; | |
11 import goodjava.lucene.api.MultiFieldParserConfig; | |
12 import goodjava.lucene.api.MoreFieldInfo; | |
1529 | 13 import luan.Luan; |
1528 | 14 import luan.LuanFunction; |
15 import luan.LuanTable; | |
1578 | 16 import luan.LuanMutable; |
1528 | 17 import luan.LuanException; |
18 import luan.LuanRuntimeException; | |
19 | |
20 | |
21 final class SupplementingConfig extends MultiFieldParserConfig { | |
1685 | 22 private final Luan luan = new Luan(); |
1528 | 23 private final LuanFunction supplementer; |
24 | |
1685 | 25 SupplementingConfig(Version luceneVersion,MultiFieldParser mfp,LuanFunction supplementer) throws LuanException { |
1528 | 26 super(luceneVersion,mfp); |
1578 | 27 LuanMutable.makeImmutable(supplementer); |
28 this.supplementer = supplementer; | |
1528 | 29 } |
30 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1562
diff
changeset
|
31 @Override public IndexWriterConfig newLuceneConfig() { |
1528 | 32 IndexWriterConfig luceneConfig = super.newLuceneConfig(); |
33 SnapshotDeletionPolicy snapshotDeletionPolicy = new SnapshotDeletionPolicy(luceneConfig.getIndexDeletionPolicy()); | |
34 luceneConfig.setIndexDeletionPolicy(snapshotDeletionPolicy); | |
35 return luceneConfig; | |
36 } | |
37 | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1562
diff
changeset
|
38 @Override public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) { |
1528 | 39 if( supplementer == null ) |
40 return super.getMoreFieldInfo(storedFields); | |
41 try { | |
1562 | 42 LuanTable tbl = toTable(storedFields); |
1578 | 43 synchronized(luan) { |
44 tbl = (LuanTable)supplementer.call(luan,tbl); | |
45 } | |
1528 | 46 if( tbl == null ) { |
47 return super.getMoreFieldInfo(storedFields); | |
48 } else { | |
1529 | 49 return new MoreFieldInfo(toLucene(tbl),Collections.emptyMap()); |
1528 | 50 } |
51 } catch(LuanException e) { | |
52 throw new LuanRuntimeException(e); | |
53 } | |
54 } | |
1529 | 55 |
1562 | 56 static LuanTable toTable(Map map) throws LuanException { |
57 LuanTable table = new LuanTable(); | |
1529 | 58 for( Object obj : map.entrySet() ) { |
59 Map.Entry entry = (Map.Entry)obj; | |
60 Object value = entry.getValue(); | |
61 if( value instanceof List ) | |
1562 | 62 value = new LuanTable((List)value); |
1529 | 63 table.rawPut( entry.getKey(), value ); |
64 } | |
65 return table; | |
66 } | |
67 | |
68 static Map<String,Object> toLucene(LuanTable table) throws LuanException { | |
69 Map<String,Object> map = new LinkedHashMap<String,Object>(); | |
1563
8fbcc4747091
remove LuanFunction.luan
Franklin Schmidt <fschmidt@gmail.com>
parents:
1562
diff
changeset
|
70 for( Map.Entry<Object,Object> entry : table.rawIterable() ) { |
1529 | 71 String name = (String)entry.getKey(); |
72 Object value = entry.getValue(); | |
73 if( value instanceof LuanTable ) { | |
74 LuanTable list = (LuanTable)value; | |
75 if( !list.isList() ) | |
76 throw new LuanException("table value for '"+name+"' must be a list"); | |
77 value = list.asList(); | |
78 } | |
79 map.put(name,value); | |
80 } | |
81 return map; | |
82 } | |
83 | |
1528 | 84 } |