Mercurial Hosting > luan
diff 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 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/SupplementingConfig.java Sun Jul 26 23:11:53 2020 -0600 +++ b/src/luan/modules/lucene/SupplementingConfig.java Mon Jul 27 12:54:31 2020 -0600 @@ -1,6 +1,8 @@ package luan.modules.lucene; import java.util.Map; +import java.util.LinkedHashMap; +import java.util.List; import java.util.Collections; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.SnapshotDeletionPolicy; @@ -8,6 +10,7 @@ import goodjava.lucene.queryparser.MultiFieldParser; import goodjava.lucene.api.MultiFieldParserConfig; import goodjava.lucene.api.MoreFieldInfo; +import luan.Luan; import luan.LuanFunction; import luan.LuanTable; import luan.LuanCloner; @@ -35,15 +38,44 @@ if( supplementer == null ) return super.getMoreFieldInfo(storedFields); try { - LuanTable tbl = LuceneIndex.toTable(supplementer.luan(),storedFields); + LuanTable tbl = toTable(supplementer.luan(),storedFields); tbl = (LuanTable)supplementer.call(tbl); if( tbl == null ) { return super.getMoreFieldInfo(storedFields); } else { - return new MoreFieldInfo(LuceneIndex.toLucene(tbl),Collections.emptyMap()); + return new MoreFieldInfo(toLucene(tbl),Collections.emptyMap()); } } catch(LuanException e) { throw new LuanRuntimeException(e); } } + + static LuanTable toTable(Luan luan,Map map) throws LuanException { + LuanTable table = new LuanTable(luan); + for( Object obj : map.entrySet() ) { + Map.Entry entry = (Map.Entry)obj; + Object value = entry.getValue(); + if( value instanceof List ) + value = new LuanTable(luan,(List)value); + table.rawPut( entry.getKey(), value ); + } + return table; + } + + static Map<String,Object> toLucene(LuanTable table) throws LuanException { + Map<String,Object> map = new LinkedHashMap<String,Object>(); + for( Map.Entry<Object,Object> entry : table.iterable() ) { + String name = (String)entry.getKey(); + Object value = entry.getValue(); + if( value instanceof LuanTable ) { + LuanTable list = (LuanTable)value; + if( !list.isList() ) + throw new LuanException("table value for '"+name+"' must be a list"); + value = list.asList(); + } + map.put(name,value); + } + return map; + } + }