Mercurial Hosting > luan
comparison src/luan/modules/lucene/SupplementingConfig.java @ 1529:e6d808f40bbc
minor
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 27 Jul 2020 12:54:31 -0600 |
parents | 3bd4d7963456 |
children | b89212fd04b5 |
comparison
equal
deleted
inserted
replaced
1528:3bd4d7963456 | 1529:e6d808f40bbc |
---|---|
1 package luan.modules.lucene; | 1 package luan.modules.lucene; |
2 | 2 |
3 import java.util.Map; | 3 import java.util.Map; |
4 import java.util.LinkedHashMap; | |
5 import java.util.List; | |
4 import java.util.Collections; | 6 import java.util.Collections; |
5 import org.apache.lucene.index.IndexWriterConfig; | 7 import org.apache.lucene.index.IndexWriterConfig; |
6 import org.apache.lucene.index.SnapshotDeletionPolicy; | 8 import org.apache.lucene.index.SnapshotDeletionPolicy; |
7 import org.apache.lucene.util.Version; | 9 import org.apache.lucene.util.Version; |
8 import goodjava.lucene.queryparser.MultiFieldParser; | 10 import goodjava.lucene.queryparser.MultiFieldParser; |
9 import goodjava.lucene.api.MultiFieldParserConfig; | 11 import goodjava.lucene.api.MultiFieldParserConfig; |
10 import goodjava.lucene.api.MoreFieldInfo; | 12 import goodjava.lucene.api.MoreFieldInfo; |
13 import luan.Luan; | |
11 import luan.LuanFunction; | 14 import luan.LuanFunction; |
12 import luan.LuanTable; | 15 import luan.LuanTable; |
13 import luan.LuanCloner; | 16 import luan.LuanCloner; |
14 import luan.LuanException; | 17 import luan.LuanException; |
15 import luan.LuanRuntimeException; | 18 import luan.LuanRuntimeException; |
33 | 36 |
34 public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) { | 37 public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) { |
35 if( supplementer == null ) | 38 if( supplementer == null ) |
36 return super.getMoreFieldInfo(storedFields); | 39 return super.getMoreFieldInfo(storedFields); |
37 try { | 40 try { |
38 LuanTable tbl = LuceneIndex.toTable(supplementer.luan(),storedFields); | 41 LuanTable tbl = toTable(supplementer.luan(),storedFields); |
39 tbl = (LuanTable)supplementer.call(tbl); | 42 tbl = (LuanTable)supplementer.call(tbl); |
40 if( tbl == null ) { | 43 if( tbl == null ) { |
41 return super.getMoreFieldInfo(storedFields); | 44 return super.getMoreFieldInfo(storedFields); |
42 } else { | 45 } else { |
43 return new MoreFieldInfo(LuceneIndex.toLucene(tbl),Collections.emptyMap()); | 46 return new MoreFieldInfo(toLucene(tbl),Collections.emptyMap()); |
44 } | 47 } |
45 } catch(LuanException e) { | 48 } catch(LuanException e) { |
46 throw new LuanRuntimeException(e); | 49 throw new LuanRuntimeException(e); |
47 } | 50 } |
48 } | 51 } |
52 | |
53 static LuanTable toTable(Luan luan,Map map) throws LuanException { | |
54 LuanTable table = new LuanTable(luan); | |
55 for( Object obj : map.entrySet() ) { | |
56 Map.Entry entry = (Map.Entry)obj; | |
57 Object value = entry.getValue(); | |
58 if( value instanceof List ) | |
59 value = new LuanTable(luan,(List)value); | |
60 table.rawPut( entry.getKey(), value ); | |
61 } | |
62 return table; | |
63 } | |
64 | |
65 static Map<String,Object> toLucene(LuanTable table) throws LuanException { | |
66 Map<String,Object> map = new LinkedHashMap<String,Object>(); | |
67 for( Map.Entry<Object,Object> entry : table.iterable() ) { | |
68 String name = (String)entry.getKey(); | |
69 Object value = entry.getValue(); | |
70 if( value instanceof LuanTable ) { | |
71 LuanTable list = (LuanTable)value; | |
72 if( !list.isList() ) | |
73 throw new LuanException("table value for '"+name+"' must be a list"); | |
74 value = list.asList(); | |
75 } | |
76 map.put(name,value); | |
77 } | |
78 return map; | |
79 } | |
80 | |
49 } | 81 } |