SOLR-1900: remove last use of TermDocs in SolrIndexSearcher

git-svn-id: https://svn.apache.org/repos/asf/lucene/dev/trunk@951209 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Yonik Seeley 2010-06-03 23:40:34 +00:00
parent f7673b59f1
commit a11fa9f0f5
1 changed files with 10 additions and 8 deletions

View File

@ -24,6 +24,7 @@ import org.apache.lucene.store.Directory;
import org.apache.lucene.store.FSDirectory;
import org.apache.lucene.util.Bits;
import org.apache.lucene.util.BytesRef;
import org.apache.lucene.util.UnicodeUtil;
import org.apache.solr.common.util.NamedList;
import org.apache.solr.common.util.SimpleOrderedMap;
import org.apache.solr.core.SolrConfig;
@ -476,14 +477,15 @@ public class SolrIndexSearcher extends IndexSearcher implements SolrInfoMBean {
* @return the first document number containing the term
*/
public int getFirstMatch(Term t) throws IOException {
TermDocs tdocs = null;
try {
tdocs = reader.termDocs(t);
if (!tdocs.next()) return -1;
return tdocs.doc();
} finally {
if (tdocs!=null) tdocs.close();
}
Fields fields = MultiFields.getFields(reader);
Terms terms = fields.terms(t.field());
if (terms == null) return -1;
BytesRef termBytes = new BytesRef();
UnicodeUtil.UTF16toUTF8(t.text(), 0, t.text().length(), termBytes);
DocsEnum docs = terms.docs(reader.getDeletedDocs(), termBytes, null);
if (docs == null) return -1;
int id = docs.docID();
return id == DocIdSetIterator.NO_MORE_DOCS ? -1 : id;
}