Search in sources :

Example 1 with DoubleIntegerDBIDKNNList

use of de.lmu.ifi.dbs.elki.database.ids.integer.DoubleIntegerDBIDKNNList in project elki by elki-project.

the class LuceneDistanceKNNQuery method getKNNForDBID.

@Override
public KNNList getKNNForDBID(DBIDRef id, int k) {
    try {
        Query query = mlt.like(range.getOffset(id));
        TopDocs topDocs = is.search(query, k);
        int rk = topDocs.scoreDocs.length;
        DoubleIntegerDBIDKNNList res = new DoubleIntegerDBIDKNNList(k, rk);
        DBIDArrayIter it = range.iter();
        for (ScoreDoc scoreDoc : topDocs.scoreDocs) {
            double dist = (scoreDoc.score > 0.) ? (1. / scoreDoc.score) : Double.POSITIVE_INFINITY;
            it.seek(scoreDoc.doc);
            res.add(dist, it);
        }
        return res;
    } catch (IOException e) {
        throw new AbortException("I/O error in lucene.", e);
    }
}
Also used : TopDocs(org.apache.lucene.search.TopDocs) Query(org.apache.lucene.search.Query) AbstractDistanceKNNQuery(de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery) DistanceQuery(de.lmu.ifi.dbs.elki.database.query.distance.DistanceQuery) DBIDArrayIter(de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter) IOException(java.io.IOException) DoubleIntegerDBIDKNNList(de.lmu.ifi.dbs.elki.database.ids.integer.DoubleIntegerDBIDKNNList) ScoreDoc(org.apache.lucene.search.ScoreDoc) AbortException(de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)

Aggregations

DBIDArrayIter (de.lmu.ifi.dbs.elki.database.ids.DBIDArrayIter)1 DoubleIntegerDBIDKNNList (de.lmu.ifi.dbs.elki.database.ids.integer.DoubleIntegerDBIDKNNList)1 DistanceQuery (de.lmu.ifi.dbs.elki.database.query.distance.DistanceQuery)1 AbstractDistanceKNNQuery (de.lmu.ifi.dbs.elki.database.query.knn.AbstractDistanceKNNQuery)1 AbortException (de.lmu.ifi.dbs.elki.utilities.exceptions.AbortException)1 IOException (java.io.IOException)1 Query (org.apache.lucene.search.Query)1 ScoreDoc (org.apache.lucene.search.ScoreDoc)1 TopDocs (org.apache.lucene.search.TopDocs)1