Skip to content

Commit

Permalink
Add rangeQuery in python binding
Browse files Browse the repository at this point in the history
  • Loading branch information
ChunjiangZhu committed Oct 22, 2019
1 parent febdcfb commit 62d71dd
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions python_bindings/nmslib.cc
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@
#include "init.h"
#include "index.h"
#include "knnquery.h"
#include "rangequery.h"
#include "knnqueue.h"
#include "methodfactory.h"
#include "space.h"
Expand Down Expand Up @@ -137,6 +138,21 @@ struct IndexWrapper {
std::unique_ptr<KNNQueue<dist_t>> res(knn.Result()->Clone());
return convertResult(res.get());
}

py::object rangeQuery(py::object input, dist_t radius) {
if (!index) {
throw std::invalid_argument("Must call createIndex or loadIndex before this method");
}

std::unique_ptr<const Object> query(readObject(input));
RangeQuery<dist_t> rq(*space, query.get(), radius);
{
py::gil_scoped_release l;
index->Search(&rq, -1);
}
std::unique_ptr<RangeQuery<dist_t>> res(rq.Result()->Clone());
return convertResult(res.get());
}

py::object knnQueryBatch(py::object input, size_t k, int num_threads) {
if (!index) {
Expand Down

0 comments on commit 62d71dd

Please sign in to comment.