开发者

Find record with values closest to those I have

I have fields A, B, C, D and need records with A,B,C,D closet to this vector MY = (2, 3, 4, 5).

MY is different on every query.

The only thing that comes to mind is sorting every time by abs(A - MY.A) + abs(B - MY.B) + ... somehow. But it should work very slow, I suppose.

Now I'm thinking of using MongoDB. If you'd say that MongoDB is not the best tool for it - I'd be glad to hear any suggestions.

GeoLocation - it takes only 2 coordinates. MY is just vector of numbers. It is not spatial. ABCD are between 1 and 10. I mean that I need to finds vector OTHER to minimalize K = |MY-OTHER|.

Thanks beforehand.

Fresh idea

Querying all records where A is in [A - s, A + s], B in [B - s, B + s] .. and then sorting them using some lo开发者_JS百科gic. s - constant based on amount of records, chosen to make query return up to 10-20 records.


It's not clear whether your vectors are actual spatial coordinates or just vectors of data.

If they are real numbers, you can use something like the cosine similarity to calculate the similarity between the two vectors. http://en.wikipedia.org/wiki/Cosine_similarity

If they are spatial coordinates, you can use a spatial index like the other poster suggested. I have had good success with the R-Tree Spatial Index which is implemented in many languages, and will allow you to do all kinds of spatial queries.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜