Mercurial Hosting > luan
diff src/luan/modules/lucene/LuceneIndex.java @ 1563:8fbcc4747091
remove LuanFunction.luan
author | Franklin Schmidt <fschmidt@gmail.com> |
---|---|
date | Mon, 09 Nov 2020 01:37:57 -0700 |
parents | b89212fd04b5 |
children | 582384548a69 |
line wrap: on
line diff
--- a/src/luan/modules/lucene/LuceneIndex.java Sun Nov 08 16:50:59 2020 -0700 +++ b/src/luan/modules/lucene/LuceneIndex.java Mon Nov 09 01:37:57 2020 -0700 @@ -171,12 +171,12 @@ analyzer = sfp.analyzer; } this.analyzer = analyzer; - this.config = new SupplementingConfig(luceneVersion,mfp,supplementer); + this.config = new SupplementingConfig(luceneVersion,mfp,luan,supplementer); wasCreated = reopen(); if( postgresSpec == null ) { postgresBackup = null; } else { - postgresBackup = new PostgresBackup(luan,postgresSpec); + postgresBackup = new PostgresBackup(postgresSpec); if( !wasCreated && postgresBackup.wasCreated ) { logger.error("rebuilding postgres backup"); rebuild_postgres_backup(luan); @@ -323,7 +323,7 @@ return writeLock.isHeldByCurrentThread(); } - public Object run_in_transaction(LuanFunction fn) + public Object run_in_transaction(Luan luan,LuanFunction fn) throws IOException, LuanException, SQLException { boolean commit = !writeLock.isHeldByCurrentThread(); @@ -332,7 +332,7 @@ try { if( commit && postgresBackup != null ) postgresBackup.begin(); - Object rtn = fn.call(); + Object rtn = fn.call(luan); ok = true; if(commit) { if( postgresBackup != null ) @@ -353,13 +353,13 @@ } // ??? - public Object run_in_lock(LuanFunction fn) throws IOException, LuanException { + public Object run_in_lock(Luan luan,LuanFunction fn) throws IOException, LuanException { if( writeLock.isHeldByCurrentThread() ) throw new RuntimeException(); writeLock.lock(); try { synchronized(this) { - return fn.call(); + return fn.call(luan); } } finally { wrote(); @@ -408,13 +408,13 @@ return (SnapshotDeletionPolicy)writer.getLuceneIndexWriter().getConfig().getIndexDeletionPolicy(); } - public Object snapshot(LuanFunction fn) throws LuanException, IOException { + public Object snapshot(Luan luan,LuanFunction fn) throws LuanException, IOException { SnapshotDeletionPolicy snapshotDeletionPolicy = snapshotDeletionPolicy(); IndexCommit ic = snapshotDeletionPolicy.snapshot(); try { String dir = fsDir.getDirectory().toString(); LuanTable fileNames = new LuanTable(new ArrayList(ic.getFileNames())); - return fn.call(dir,fileNames); + return fn.call(luan,dir,fileNames); } finally { snapshotDeletionPolicy.release(ic); } @@ -464,13 +464,12 @@ final Query query; int docID; - DocFn(Luan luan,IndexSearcher searcher,Query query) { - super(luan); + DocFn(IndexSearcher searcher,Query query) { this.searcher = searcher; this.query = query; } - @Override public Object call(Object[] args) throws LuanException { + @Override public Object call(Luan luan,Object[] args) throws LuanException { try { LuanTable doc = toTable(searcher.doc(docID)); if( args.length > 0 && "explain".equals(args[0]) ) { @@ -523,7 +522,7 @@ close(openSearcher()); } - public int advanced_search( String queryStr, LuanFunction fn, Integer n, String sortStr ) + public int advanced_search( final Luan luan, String queryStr, LuanFunction fn, Integer n, String sortStr ) throws LuanException, IOException, ParseException { Utils.checkNotNull(queryStr); @@ -536,12 +535,12 @@ if( fn!=null && n==null ) { if( sortStr != null ) throw new LuanException("sort must be nil when n is nil"); - final DocFn docFn = new DocFn(fn.luan(),searcher,query); + final DocFn docFn = new DocFn(searcher,query); MyCollector col = new MyCollector() { @Override public void collect(int doc) { try { docFn.docID = docBase + doc; - fn.call(++i,docFn); + fn.call(luan,++i,docFn); } catch(LuanException e) { throw new LuanRuntimeException(e); } @@ -562,11 +561,11 @@ Sort sort = sortStr==null ? null : GoodQueryParser.parseSort(mfp,sortStr); TopDocs td = sort==null ? searcher.search(query,n) : searcher.search(query,n,sort); final ScoreDoc[] scoreDocs = td.scoreDocs; - DocFn docFn = new DocFn(fn.luan(),searcher,query); + DocFn docFn = new DocFn(searcher,query); for( int i=0; i<scoreDocs.length; i++ ) { ScoreDoc scoreDoc = scoreDocs[i]; docFn.docID = scoreDoc.doc; - fn.call(i+1,docFn,scoreDoc.score); + fn.call(luan,i+1,docFn,scoreDoc.score); } return td.totalHits; } finally { @@ -575,13 +574,13 @@ } } - public Object search_in_transaction(LuanFunction fn) throws LuanException, IOException { + public Object search_in_transaction(Luan luan,LuanFunction fn) throws LuanException, IOException { if( threadLocalSearcher.get() != null ) throw new LuanException("can't nest search_in_transaction calls"); IndexSearcher searcher = openSearcher(); threadLocalSearcher.set(searcher); try { - return fn.call(); + return fn.call(luan); } finally { threadLocalSearcher.set(null); close(searcher); @@ -616,7 +615,7 @@ } }; - public LuanFunction highlighter(String queryStr,final LuanFunction formatter,final Integer fragmentSize,String dotdotdot) + public LuanFunction highlighter(final Luan luan,String queryStr,final LuanFunction formatter,final Integer fragmentSize,String dotdotdot) throws ParseException { Query query = GoodQueryParser.parseQuery(mfp,queryStr); @@ -625,7 +624,7 @@ if( tokenGroup.getTotalScore() <= 0 ) return originalText; try { - return (String)Luan.first(formatter.call(originalText)); + return (String)Luan.first(formatter.call(luan,originalText)); } catch(LuanException e) { throw new LuanRuntimeException(e); } @@ -637,8 +636,8 @@ chooser.setTextFragmenter( new SimpleSpanFragmenter(queryScorer,fragmentSize) ); final Highlighter hl = new Highlighter(fmt,queryScorer); hl.setTextFragmenter( new NullFragmenter() ); - return new LuanFunction(false) { // ??? - @Override public String call(Object[] args) throws LuanException { + return new LuanFunction() { + @Override public String call(Luan luan,Object[] args) throws LuanException { String text = (String)args[0]; try { if( chooser != null ) { @@ -791,23 +790,23 @@ logger.info("end relog"); } - public void restore_from_log(LuanFunction handler) + public void restore_from_log(Luan luan,LuanFunction handler) throws IOException, LuanException, SQLException, ParseException { LoggingIndexWriter loggingWriter = (LoggingIndexWriter)writer; if( wasCreated && !loggingWriter.wasCreated ) { logger.error("restoring from log"); - force_restore_from_log(handler); + force_restore_from_log(luan,handler); } } - public void force_restore_from_log(LuanFunction handler) + public void force_restore_from_log(Luan luan,LuanFunction handler) throws IOException { logger.warn("start force_restore_from_log"); if( writeLock.isHeldByCurrentThread() ) throw new RuntimeException(); - OpDoer opDoer = handler==null ? null : new LuanOpDoer(writer,handler); + OpDoer opDoer = handler==null ? null : new LuanOpDoer(writer,luan,handler); writeLock.lock(); boolean ok = false; try { @@ -829,7 +828,7 @@ logger.warn("end force_restore_from_log"); } - public void check(Luan luan) throws IOException, SQLException, LuanException, ParseException { + public void check() throws IOException, SQLException, LuanException, ParseException { boolean hasPostgres = postgresBackup != null; String msg = "start check"; if( hasPostgres ) @@ -845,12 +844,12 @@ } if( hasPostgres ) { logger.info("postgres check"); - checkPostgres(luan); + checkPostgres(); } logger.info("end check"); } - private void checkPostgres(Luan luan) + private void checkPostgres() throws IOException, SQLException, LuanException, ParseException { final PostgresBackup.Checker postgresChecker = postgresBackup.newChecker(); @@ -872,7 +871,7 @@ final int nPostgres = idsPostgres.size(); int iLucene = 0; int iPostgres = 0; - LuanToString lts = new LuanToString(luan,null,null); + LuanToString lts = new LuanToString(null,null); lts.settingsInit.strict = true; lts.settingsInit.numberTypes = true; while( iLucene < nLucene && iPostgres < nPostgres ) {