view src/nabble/model/lucene/LuceneSearcherImpl.java @ 67:9d0fefce6985 default tip

remove rest_group_control
author Franklin Schmidt <fschmidt@gmail.com>
date Wed, 06 Nov 2024 21:21:53 -0700
parents 7ecd1a4ef557
children
line wrap: on
line source

package nabble.model.lucene;

import java.io.IOException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.apache.lucene.document.Document;
import org.apache.lucene.index.CorruptIndexException;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.Filter;
import org.apache.lucene.search.Collector;
import org.apache.lucene.search.TopDocs;
import org.apache.lucene.search.TopFieldDocs;
import org.apache.lucene.search.Sort;


final class LuceneSearcherImpl implements LuceneSearcher {
	private static final Logger logger = LoggerFactory.getLogger(LuceneSearcherImpl.class);

	private final LuceneSearcher searcher;
	private boolean isClosed = false;

	LuceneSearcherImpl(LuceneSearcher searcher) {
		this.searcher = searcher;
	}

	public void close() throws IOException {
		if( !isClosed ) {
			searcher.close();
			isClosed = true;
		}
	}

	@Override protected void finalize() throws Throwable {
		if( !isClosed ) {
			logger.error("didn't close IndexSearcher"/*,initException*/);
			close();
		}
		super.finalize();
	}

	public void search(Query query,Collector results) throws IOException {
		searcher.search(query,results);
	}

	public void search(Query query,Filter filter,Collector results) throws IOException {
		searcher.search(query,filter,results);
	}

	public TopDocs search(Query query,int n) throws IOException {
		return searcher.search(query,n);
	}

	public TopDocs search(Query query,Filter filter,int n) throws IOException {
		return searcher.search(query,filter,n);
	}

	public TopFieldDocs search(Query query,Filter filter,int n,Sort sort) throws IOException {
		return searcher.search(query,filter,n,sort);
	}

	public Document doc(int i) throws CorruptIndexException, IOException {
		return searcher.doc(i);
	}
}