Mercurial Hosting > luan
view src/luan/modules/lucene/SupplementingConfig.java @ 1528:3bd4d7963456
use goodjava/lucene/api
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Sun, 26 Jul 2020 23:11:53 -0600 |
parents | |
children | e6d808f40bbc |
line wrap: on
line source
package luan.modules.lucene; import java.util.Map; import java.util.Collections; import org.apache.lucene.index.IndexWriterConfig; import org.apache.lucene.index.SnapshotDeletionPolicy; import org.apache.lucene.util.Version; import goodjava.lucene.queryparser.MultiFieldParser; import goodjava.lucene.api.MultiFieldParserConfig; import goodjava.lucene.api.MoreFieldInfo; import luan.LuanFunction; import luan.LuanTable; import luan.LuanCloner; import luan.LuanException; import luan.LuanRuntimeException; final class SupplementingConfig extends MultiFieldParserConfig { private final LuanFunction supplementer; SupplementingConfig(Version luceneVersion,MultiFieldParser mfp,LuanFunction supplementer) { super(luceneVersion,mfp); LuanCloner cloner = new LuanCloner(LuanCloner.Type.COMPLETE); this.supplementer = (LuanFunction)cloner.get(supplementer); } public IndexWriterConfig newLuceneConfig() { IndexWriterConfig luceneConfig = super.newLuceneConfig(); SnapshotDeletionPolicy snapshotDeletionPolicy = new SnapshotDeletionPolicy(luceneConfig.getIndexDeletionPolicy()); luceneConfig.setIndexDeletionPolicy(snapshotDeletionPolicy); return luceneConfig; } public MoreFieldInfo getMoreFieldInfo(Map<String,Object> storedFields) { if( supplementer == null ) return super.getMoreFieldInfo(storedFields); try { LuanTable tbl = LuceneIndex.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()); } } catch(LuanException e) { throw new LuanRuntimeException(e); } } }