IndexTank: how to query without a query string, geolocation only

337 views Asked by At

I know how to query IndexTank with a query string, with or without geolocation. But how do you query with no query string and only geolocation?

        index.addFunction(5, "-miles(d[0], d[1], q[0], q[1])");
        results = index.search(Query.forString(queryString)
                .withScoringFunction(5)
                .withQueryVariable(0, latitude)
                .withQueryVariable(1, longitude));

If the queryString is null or an empty string it doesn't work.

Thanks.

1

There are 1 answers

1
jhandl On BEST ANSWER

If you want to fetch all documents that are within a certain distance from a point, you need to issue a query that matches all documents and use a function filter on the scoring function that calculates the distance.

For example, if all your documents have a "match" field with the value "all", you can search for:

  results = index.search(Query.forString("match:all")
                    .withScoringFunction(5)
                    .withQueryVariable(0, latitude)
                    .withQueryVariable(1, longitude)
                    .withFunctionFilter(5, 0, 10));

This would get all documents within 10 miles of (lat,long).