Problems with two key ranges in couchdb

I have a problem getting the correct results in my coordinate system. To explain my system, I have a simple database with x_axis, y_axis and name columns. I do not need to receive all the data, I just need to display part of it.

For example, I have a coordinate system that has 10:10 (a value from x_axis from -10 to 10 and from y_axis from -10 to 10), and I want to display only 49 coordinates. In the sql query, I can do it something like this: "select * from the coordinate where x_axis> = -3 and x_axis <= 3 and y_axis> = -3 y_axis <= 3"

I tried this function but did not succeed:

   "by_range": {
       "map": "function(doc) { emit([doc.x_axis, doc.y_axis], doc) }"
   }
?

by_range StartKey = [- 3, -3] & EndKey = [3.3]

I got the wrong results:

-3x-3 -3x-2 -3x-1 -3x0 -3x1 -3x2 -3x3 <- should not display this part → -3x4 -3x5 -3x6 -3x7 -3x8 -3x9 -3x10 <- the end should not display this part → ..... to 3x3

to better understand my project, here is a screenshot that I want to take:

+3
source share
3 answers
by_range?startkey=[-3,-3]&endkey=[3,3]

You use this as a WHERE clause. Couchdb does not understand the meaning of "startkey" and "endkey", it just uses them to know when to start and stop outputting results.

For example, take the following result set:

doc1
doc2
doc3
doc4

If I applied this query:

StartKey = doc2 &? EndKey = doc3

The result set will be:

doc2
doc3

To apply the range in your example, I would change the map function:

function(doc) {
 if (doc.x <= 3 && doc.x >= -3 && doc.y <= 3 && doc.y >= -3)
   emit([doc.x, doc.y], doc)
}

:

CouchDB:

" CouchDB , , ".

, , , .

function(doc) {
 emit(doc.x * doc.y, doc)
}

:

by_range?startkey=-9&endkey=9

, -

startkey = (x1*y1)
endkey = (x2*y2)
+2

:

2 :

  • 2 .
  • couchdb-lucene
0

You can do something like a WHERE clause with a few keys and the technique described in this article .

0
source

Source: https://habr.com/ru/post/1727092/


All Articles