Skip to content

Commit 8561ae5

Browse files
DOC-9450: Update SEARCH_META(..) instructions and examples
1 parent 0074585 commit 8561ae5

File tree

2 files changed

+270
-39
lines changed

2 files changed

+270
-39
lines changed

modules/fts/pages/fts-searching-from-N1QL.adoc

Lines changed: 135 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -5,11 +5,57 @@ Search functions enable you to use full text search queries directly within a N1
55
== Prerequisites
66

77
To use any of the search functions, the Search service must be available on the cluster.
8-
It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform.
8+
It is required for you to create suitable full text indexes for the searches that you want to perform.
99

1010
[NOTE]
1111
--
12-
The examples in this page all assume that demonstration full text indexes have been created.
12+
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise ..
13+
[source,json]
14+
----
15+
{
16+
"name": "travel-sample-inventory-hotels",
17+
"type": "fulltext-index",
18+
"params": {
19+
"doc_config": {
20+
"mode": "scope.collection.type_field",
21+
"type_field": "type"
22+
},
23+
"mapping": {
24+
"default_analyzer": "standard",
25+
"default_datetime_parser": "dateTimeOptional",
26+
"default_field": "_all",
27+
"default_mapping": {
28+
"dynamic": true,
29+
"enabled": false
30+
},
31+
"default_type": "_default",
32+
"docvalues_dynamic": false,
33+
"index_dynamic": true,
34+
"store_dynamic": false,
35+
"type_field": "_type",
36+
"types": {
37+
"inventory.hotel": {
38+
"dynamic": true,
39+
"enabled": true
40+
}
41+
}
42+
},
43+
"store": {
44+
"indexType": "scorch",
45+
"segmentVersion": 15
46+
}
47+
},
48+
"sourceType": "gocbcore",
49+
"sourceName": "travel-sample",
50+
"sourceUUID": "",
51+
"sourceParams": {},
52+
"planParams": {
53+
"indexPartitions": 1
54+
},
55+
"uuid": ""
56+
}
57+
----
58+
1359
--
1460

1561
=== Authorization
@@ -203,33 +249,29 @@ The following queries are equivalent:
203249
[source,n1ql]
204250
----
205251
SELECT META(t1).id
206-
FROM `travel-sample`.inventory.airline AS t1
252+
FROM `travel-sample`.inventory.hotel AS t1
207253
WHERE SEARCH(t1.country, "+United +States");
208254
----
209255
210256
[source,n1ql]
211257
----
212258
SELECT META(t1).id
213-
FROM `travel-sample`.inventory.airline AS t1
259+
FROM `travel-sample`.inventory.hotel AS t1
214260
WHERE SEARCH(t1, "country:\"United States\"");
215261
----
216262
217263
.Results
218264
[source,json]
219265
----
220266
[
221-
222-
{
223-
"id": "airline_10"
224-
},
225267
{
226-
"id": "airline_10123"
268+
"id": "hotel_26215"
227269
},
228270
{
229-
"id": "airline_10226"
271+
"id": "hotel_7396"
230272
},
231273
{
232-
"id": "airline_10748"
274+
"id": "hotel_32177"
233275
},
234276
...
235277
]
@@ -350,8 +392,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
350392
----
351393
352394
If the full text search index being queried has its default mapping disabled and has a custom type mapping defined, the query needs to specify the type explicitly.
353-
354-
//The above query uses the demonstration index xref:fts:fts-demonstration-indexes.adoc#travel-sample-index-hotel-description[travel-sample-index-hotel-description], which has the custom type mapping "hotel".
395+
The above query uses the following index definition ..
396+
[source,json]
397+
----
398+
{
399+
"name": "travel-sample-index-hotel-description",
400+
"type": "fulltext-index",
401+
"params": {
402+
"doc_config": {
403+
"mode": "type_field",
404+
"type_field": "type"
405+
},
406+
"mapping": {
407+
"analysis": {
408+
"analyzers": {
409+
"myUnicodeAnalyzer": {
410+
"tokenizer": "unicode",
411+
"type": "custom"
412+
}
413+
}
414+
},
415+
"default_analyzer": "standard",
416+
"default_datetime_parser": "dateTimeOptional",
417+
"default_field": "_all",
418+
"default_mapping": {
419+
"dynamic": true,
420+
"enabled": false
421+
},
422+
"default_type": "_default",
423+
"index_dynamic": true,
424+
"store_dynamic": true,
425+
"type_field": "type",
426+
"types": {
427+
"hotel": {
428+
"dynamic": false,
429+
"enabled": true,
430+
"properties": {
431+
"description": {
432+
"enabled": true,
433+
"dynamic": false,
434+
"fields": [
435+
{
436+
"include_in_all": true,
437+
"include_term_vectors": true,
438+
"index": true,
439+
"name": "description",
440+
"store": true,
441+
"type": "text"
442+
}
443+
]
444+
}
445+
}
446+
}
447+
}
448+
},
449+
"store": {
450+
"indexType": "scorch"
451+
}
452+
},
453+
"sourceType": "couchbase",
454+
"sourceName": "travel-sample",
455+
"sourceUUID": "",
456+
"sourceParams": {},
457+
"planParams": {
458+
"indexPartitions": 1
459+
},
460+
"uuid": ""
461+
}
462+
----
355463
356464
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
357465
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +614,10 @@ AND SEARCH(t1, {
506614
----
507615
[
508616
{
617+
"meta": {
618+
"id": "hotel_17598",
619+
"score": 2.1256278997816835
620+
},
509621
"name": "Marina del Rey Marriott"
510622
}
511623
]
@@ -569,16 +681,19 @@ LIMIT 3;
569681
----
570682
[
571683
{
572-
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
573-
"name": "The Royal Victoria Hotel"
684+
"description": "370 guest rooms offering both water and mountain view.",
685+
"name": "Marina del Rey Marriott",
686+
"score": 2.1256278997816835
574687
},
575688
{
576-
"description": "370 guest rooms offering both water and mountain view.",
577-
"name": "Marina del Rey Marriott"
689+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
690+
"name": "Clwydian Holidays",
691+
"score": 1.6956645086702617
578692
},
579693
{
580-
"description": "This small family run hotel captures the spirit of Mull and is a perfect rural holiday retreat. The mountain and sea blend together to give fantastic, panoramic views from the hotel which is in an elevated position on the shoreline. Panoramic views are also available from the bar and restaurant which serves local produce 7 days a week.",
581-
"name": "The Glenforsa Hotel"
694+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
695+
"name": "The Royal Victoria Hotel",
696+
"score": 1.5030458987111712
582697
}
583698
]
584699
----
@@ -682,4 +797,4 @@ WHERE reviews.content LIKE "%travel%";
682797
SELECT META().id
683798
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
684799
WHERE content LIKE "%travel%";
685-
----
800+
----

0 commit comments

Comments
 (0)