Skip to content

Commit 70c21ad

Browse files
dplewisflovilmart
authored andcommitted
Rest Doc for Full Text Search and withinPolygon (#444)
* Rest Doc for full text search and withinPolygon * typos * links
1 parent 8869036 commit 70c21ad

File tree

2 files changed

+164
-1
lines changed

2 files changed

+164
-1
lines changed

_includes/rest/geopoints.md

Lines changed: 70 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -81,7 +81,7 @@ result = json.loads(connection.getresponse().read())
8181
print result
8282
</code></pre>
8383

84-
This will return a list of results ordered by distance from 30.0 latitude and -20.0 longitude. The first result will be the nearest object. (Note that if an explicit `order` parameter is supplied, it will take precedence over the distance ordering.) For example, here are two results returned for the above query:
84+
This will return a list of results ordered by distance from 30.0 latitude and -20.0 longitude. The first result will be the nearest object. (Note that if an explicit `order` parameter is supplied, it will take precedence over the distance ordering.) For example, here are two results returned for the above query:
8585

8686
<pre><code class="json">
8787
{
@@ -208,6 +208,75 @@ result = json.loads(connection.getresponse().read())
208208
print result
209209
</code></pre>
210210

211+
* Starting with Parse-Server 2.5.0
212+
213+
It's also possible to query for the set of objects that are contained within or on the bounds of a polygon. `$polygon` allows for opened or closed paths, minimum of 3 `GeoPoint`'s.
214+
215+
<pre><code class="bash">
216+
curl -X GET \
217+
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
218+
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
219+
-G \
220+
--data-urlencode 'where={
221+
"location": {
222+
"$geoWithin": {
223+
"$polygon": [
224+
{
225+
"__type": "GeoPoint",
226+
"latitude": 25.774,
227+
"longitude": -80.190
228+
},
229+
{
230+
"__type": "GeoPoint",
231+
"latitude": 18.466,
232+
"longitude": -66.118
233+
},
234+
{
235+
"__type": "GeoPoint",
236+
"latitude": 32.321,
237+
"longitude": -64.757
238+
}
239+
]
240+
}
241+
}
242+
}' \
243+
https://api.parse.com/1/classes/PizzaPlaceObject
244+
</code></pre>
245+
<pre><code class="python">
246+
import json,httplib,urllib
247+
connection = httplib.HTTPSConnection('api.parse.com', 443)
248+
params = urllib.urlencode({"where":json.dumps({
249+
"location": {
250+
"$geoWithin": {
251+
"$polygon": [
252+
{
253+
"__type": "GeoPoint",
254+
"latitude": 25.774,
255+
"longitude": -80.190
256+
},
257+
{
258+
"__type": "GeoPoint",
259+
"latitude": 18.466,
260+
"longitude": -66.118
261+
},
262+
{
263+
"__type": "GeoPoint",
264+
"latitude": 32.321,
265+
"longitude": -64.757
266+
}
267+
]
268+
}
269+
}
270+
})})
271+
connection.connect()
272+
connection.request('GET', '/1/classes/PizzaPlaceObject?%s' % params, '', {
273+
"X-Parse-Application-Id": "${APPLICATION_ID}",
274+
"X-Parse-REST-API-Key": "${REST_API_KEY}"
275+
})
276+
result = json.loads(connection.getresponse().read())
277+
print result
278+
</code></pre>
279+
211280
## Caveats
212281

213282
At the moment there are a couple of things to watch out for:

_includes/rest/queries.md

Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -92,6 +92,7 @@ The values of the `where` parameter also support comparisons besides exact match
9292
| $dontSelect | Requires that a key's value not match a value for a key in the result of a different query |
9393
| $all | Contains all of the given values |
9494
| $regex | Requires that a key's value match a regular expression |
95+
| $text | Performs a full text search on indexed fields |
9596

9697
For example, to retrieve scores between 1000 and 3000, including the endpoints, we could issue:
9798

@@ -556,6 +557,99 @@ The above example will match any `BarbecueSauce` objects where the value in the
556557

557558
Queries that have regular expression constraints are very expensive, especially for classes with over 100,000 records. Parse restricts how many such operations can be run on a particular app at any given time.
558559

560+
* Starting with Parse-Server 2.5.0
561+
562+
For efficient search capabilities use the `$text` operator. By creating indexes on one or more columns your strings are turned into tokens for full text search functionality.
563+
564+
The format `{"$text": {"$search": {parameters}}}`
565+
566+
| Parameter | Use |
567+
|--------------------------------------------------------------------------------------|
568+
| $term | Specify a field to search (Required) |
569+
| $language | Determines the list of stop words and the rules for tokenizer. |
570+
| $caseSensitive | Enable or disable case sensitive search. |
571+
| $diacriticSensitive | Enable or disable diacritic sensitive search |
572+
573+
Please refer to your database documentation on Full Text Search to setup your indexes, weights and limitations.
574+
575+
<a href="https://docs.mongodb.com/v3.2/text-search/">Mongo 3.2 Full Text Search</a>
576+
577+
<a href="https://docs.mongodb.com/manual/reference/operator/query/text/">Mongo 3.4 Full Text Search</a>
578+
579+
<a href="https://www.postgresql.org/docs/9.5/static/textsearch.html">Postgres 9.5 Full Text Search</a>
580+
581+
Note: Postgres doesn't support `$caseSensitive` for Full Text Search, please use `$regex` above or create a lowercase column in your DB. Postgres supports `$diacriticSensitive: true` by default but `$diacriticSensitive: false` is not supported. To use false automatically, please install Postgres Unaccent Extension and update your text search configuration.
582+
583+
<pre><code class="bash">
584+
# Finds strings that contains "Daddy"
585+
curl -X GET \
586+
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
587+
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
588+
-G \
589+
--data-urlencode 'where={"name":{"$text":{"$search":{"$term":"Daddy"}}}}' \
590+
https://api.parse.com/1/classes/BarbecueSauce
591+
</code></pre>
592+
<pre><code class="python">
593+
# Finds barbecue sauces that contains "Daddy"
594+
import json,httplib,urllib
595+
connection = httplib.HTTPSConnection('api.parse.com', 443)
596+
params = urllib.urlencode({"where":json.dumps({
597+
"name": {
598+
"$text": {
599+
"$search": {
600+
"$term": "Daddy"
601+
}
602+
}
603+
}
604+
})})
605+
connection.connect()
606+
connection.request('GET', '/1/classes/BarbecueSauce?%s' % params, '', {
607+
"X-Parse-Application-Id": "${APPLICATION_ID}",
608+
"X-Parse-REST-API-Key": "${REST_API_KEY}"
609+
})
610+
result = json.loads(connection.getresponse().read())
611+
print result
612+
</code></pre>
613+
614+
`$text` allows for sorting by `$score`. The text score signifies how well the string matched the search term(s) based on weights.
615+
616+
<pre><code class="bash">
617+
# Finds strings that contains "Daddy" ordered by relevance
618+
curl -X GET \
619+
-H "X-Parse-Application-Id: ${APPLICATION_ID}" \
620+
-H "X-Parse-REST-API-Key: ${REST_API_KEY}" \
621+
-G \
622+
--data-urlencode 'where={"name":{"$text":{"$search":{"$term":"Daddy"}}}}' \
623+
--data-urlencode 'order="$score"' \
624+
--data-urlencode 'key="$score"' \
625+
https://api.parse.com/1/classes/BarbecueSauce
626+
</code></pre>
627+
<pre><code class="python">
628+
# Finds string that contains "Daddy" ordered by relevance
629+
import json,httplib,urllib
630+
connection = httplib.HTTPSConnection('api.parse.com', 443)
631+
params = urllib.urlencode({"where":json.dumps({
632+
"name": {
633+
"$text": {
634+
"$search": {
635+
"$term": "Daddy"
636+
}
637+
}
638+
}
639+
}),
640+
"order":"$score",
641+
"keys":"$score",
642+
})
643+
connection.connect()
644+
connection.request('GET', '/1/classes/BarbecueSauce?%s' % params, '', {
645+
"X-Parse-Application-Id": "${APPLICATION_ID}",
646+
"X-Parse-REST-API-Key": "${REST_API_KEY}"
647+
})
648+
result = json.loads(connection.getresponse().read())
649+
print result
650+
</code></pre>
651+
652+
Note: Both keys and order are required to sort by `$score`. You have to manually set weights on Postgres to use `$score`.
559653

560654
## Relational Queries
561655

0 commit comments

Comments
 (0)