From 62d71dde0c6d0c9c947068d0da823d38de2725fc Mon Sep 17 00:00:00 2001 From: ChunjiangZhu Date: Tue, 22 Oct 2019 12:08:16 -0400 Subject: [PATCH] Add rangeQuery in python binding --- python_bindings/nmslib.cc | 16 ++++++++++++++++ 1 file changed, 16 insertions(+) diff --git a/python_bindings/nmslib.cc b/python_bindings/nmslib.cc index 527e5a6..980b0b8 100644 --- a/python_bindings/nmslib.cc +++ b/python_bindings/nmslib.cc @@ -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" @@ -137,6 +138,21 @@ struct IndexWrapper { std::unique_ptr> 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 query(readObject(input)); + RangeQuery rq(*space, query.get(), radius); + { + py::gil_scoped_release l; + index->Search(&rq, -1); + } + std::unique_ptr> res(rq.Result()->Clone()); + return convertResult(res.get()); + } py::object knnQueryBatch(py::object input, size_t k, int num_threads) { if (!index) {