Skip to content

Commit eb62188

Browse files
committed
add search and geo snippets
1 parent c2db983 commit eb62188

1 file changed

Lines changed: 36 additions & 0 deletions

File tree

snippets/firestore/firestore_pipelines.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2994,6 +2994,42 @@ def search_score():
29942994
print(result)
29952995

29962996

2997+
def search_score_sort():
2998+
# [START search_score_sort]
2999+
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches, Score
3000+
from google.cloud.firestore_v1.pipeline_stages import SearchOptions
3001+
3002+
results = (
3003+
client.pipeline()
3004+
.collection("restaurants")
3005+
.search(
3006+
SearchOptions(
3007+
query=DocumentMatches("waffles"),
3008+
sort=Score().descending(),
3009+
)
3010+
)
3011+
.execute()
3012+
)
3013+
# [END search_score_sort]
3014+
for result in results:
3015+
print(result)
3016+
3017+
3018+
def search_geospatial():
3019+
# [START search_geospatial]
3020+
from google.cloud.firestore_v1.pipeline_expressions import DocumentMatches
3021+
3022+
results = (
3023+
client.pipeline()
3024+
.collection("restaurants")
3025+
.search(DocumentMatches('"belgian waffles"'))
3026+
.execute()
3027+
)
3028+
# [END search_geospatial]
3029+
for result in results:
3030+
print(result)
3031+
3032+
29973033
def define_stage_data():
29983034
# [START define_stage_data]
29993035
client.collection("Authors").document("author_123").set(

0 commit comments

Comments
 (0)