Skip to main content

Phrase and Proximity Search

Phrase search enables you to search for phrases and nearby words in full text.

Use the following cURL example to add an identity analyzer to an existing search view. In this example, the search view is sample_view.

curl --location --request POST 'https://<HOST>/_fabric/Hotels/_api/search/view' \
--header 'Content-Type: application/json' \
--header 'Accept: application/json' \
--header 'Authorization: <BEARER_TOKEN>' \
--data-raw '{
"name": "sample_view",
"links": {
"hotel_reviews": {
"analyzers": [],
"fields": {
"Review_Text": {
"analyzers": [
"text_en"
]
}
}
}
},
"type": "search"
}
'

This example queries all reviews that mention rooms are small and displays the hotel name and rating:

FOR review IN sample_view
SEARCH ANALYZER(PHRASE(review.Review_Text, "rooms are small"), "text_en")
RETURN {
Property_Name: review.Property_Name,
Review_Rating: review.Review_Rating
}

The displayed result:

Property_NameReview_Rating
The Savoy2
Ridgemount Hotel4
Marble Arch Hotel3
Hotel Xenia, Autograph Collection5
......

Alternatively, you can use the PHRASE() function to specify wild card tokens between words. This example queries reviews which specify the number of nights the reviewer has stayed in the hotel:

FOR review IN sample_view
SEARCH ANALYZER(PHRASE(review.Review_Text, "for", 1, "nights"), "text_en")
RETURN {
Property_Name: review.Property_Name,
Review_Rating: review.Review_Rating
}