Skip to content

Commit b33e8d6

Browse files
DOC-9450: Update SEARCH_META(..) instructions and examples
1 parent 8e2024b commit b33e8d6

File tree

2 files changed

+224
-39
lines changed

2 files changed

+224
-39
lines changed

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

Lines changed: 112 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-
222267
{
223-
"id": "airline_10"
268+
"id": "hotel_26215"
224269
},
225270
{
226-
"id": "airline_10123"
271+
"id": "hotel_7396"
227272
},
228273
{
229-
"id": "airline_10226"
230-
},
231-
{
232-
"id": "airline_10748"
274+
"id": "hotel_32177"
233275
},
234276
...
235277
]
@@ -350,8 +392,51 @@ 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-hotels",
400+
"type": "fulltext-index",
401+
"params": {
402+
"doc_config": {
403+
"mode": "type_field",
404+
"type_field": "type"
405+
},
406+
"mapping": {
407+
"default_analyzer": "standard",
408+
"default_datetime_parser": "dateTimeOptional",
409+
"default_field": "_all",
410+
"default_mapping": {
411+
"dynamic": true,
412+
"enabled": false
413+
},
414+
"default_type": "_default",
415+
"index_dynamic": true,
416+
"store_dynamic": true,
417+
"type_field": "type",
418+
"types": {
419+
"hotel": {
420+
"dynamic": true,
421+
"enabled": true
422+
}
423+
}
424+
},
425+
"store": {
426+
"indexType": "scorch",
427+
"segmentVersion": 15
428+
}
429+
},
430+
"sourceType": "gocbcore",
431+
"sourceName": "travel-sample",
432+
"sourceUUID": "",
433+
"sourceParams": {},
434+
"planParams": {
435+
"indexPartitions": 1
436+
},
437+
"uuid": ""
438+
}
439+
----
355440
356441
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
357442
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +591,10 @@ AND SEARCH(t1, {
506591
----
507592
[
508593
{
594+
"meta": {
595+
"id": "hotel_17598",
596+
"score": 2.1256278997816835
597+
},
509598
"name": "Marina del Rey Marriott"
510599
}
511600
]
@@ -569,16 +658,19 @@ LIMIT 3;
569658
----
570659
[
571660
{
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"
661+
"description": "370 guest rooms offering both water and mountain view.",
662+
"name": "Marina del Rey Marriott",
663+
"score": 2.1256278997816835
574664
},
575665
{
576-
"description": "370 guest rooms offering both water and mountain view.",
577-
"name": "Marina del Rey Marriott"
666+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
667+
"name": "Clwydian Holidays",
668+
"score": 1.6956645086702617
578669
},
579670
{
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"
671+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
672+
"name": "The Royal Victoria Hotel",
673+
"score": 1.5030458987111712
582674
}
583675
]
584676
----
@@ -682,4 +774,4 @@ WHERE reviews.content LIKE "%travel%";
682774
SELECT META().id
683775
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
684776
WHERE content LIKE "%travel%";
685-
----
777+
----

modules/n1ql/pages/n1ql-language-reference/searchfun.adoc

Lines changed: 112 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -10,12 +10,58 @@
1010
=== Prerequisites
1111

1212
To use any of the search functions, the Search service must be available on the cluster.
13-
It is also recommended, but not required, that you should create suitable full text indexes for the searches that you need to perform.
13+
It is required for you to create suitable full text indexes for the searches that you want to perform.
1414
For more information, refer to xref:fts:fts-quickstart-guide.adoc#preparing-for-full-text-searches[Preparing for Full Text Searches].
1515

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

2167
[float]
@@ -211,33 +257,29 @@ The following queries are equivalent:
211257
[source,n1ql]
212258
----
213259
SELECT META(t1).id
214-
FROM `travel-sample`.inventory.airline AS t1
260+
FROM `travel-sample`.inventory.hotel AS t1
215261
WHERE SEARCH(t1.country, "+United +States");
216262
----
217263
218264
[source,n1ql]
219265
----
220266
SELECT META(t1).id
221-
FROM `travel-sample`.inventory.airline AS t1
267+
FROM `travel-sample`.inventory.hotel AS t1
222268
WHERE SEARCH(t1, "country:\"United States\"");
223269
----
224270
225271
.Results
226272
[source,json]
227273
----
228274
[
229-
230275
{
231-
"id": "airline_10"
276+
"id": "hotel_26215"
232277
},
233278
{
234-
"id": "airline_10123"
279+
"id": "hotel_7396"
235280
},
236281
{
237-
"id": "airline_10226"
238-
},
239-
{
240-
"id": "airline_10748"
282+
"id": "hotel_32177"
241283
},
242284
...
243285
]
@@ -334,7 +376,7 @@ As an alternative, you could limit the number of results and order them using th
334376
[source,n1ql]
335377
----
336378
SELECT META(t1).id
337-
FROM `travel-sample`.inventory.hotel AS t1
379+
FROM `travel-sample` AS t1
338380
WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
339381
----
340382
@@ -358,7 +400,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
358400
----
359401
360402
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.
361-
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".
403+
The above query uses the following index definition ..
404+
[source,json]
405+
----
406+
{
407+
"name": "travel-sample-hotels",
408+
"type": "fulltext-index",
409+
"params": {
410+
"doc_config": {
411+
"mode": "type_field",
412+
"type_field": "type"
413+
},
414+
"mapping": {
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": true,
429+
"enabled": true
430+
}
431+
}
432+
},
433+
"store": {
434+
"indexType": "scorch",
435+
"segmentVersion": 15
436+
}
437+
},
438+
"sourceType": "gocbcore",
439+
"sourceName": "travel-sample",
440+
"sourceUUID": "",
441+
"sourceParams": {},
442+
"planParams": {
443+
"indexPartitions": 1
444+
},
445+
"uuid": ""
446+
}
447+
----
362448
363449
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-creating-indexes.adoc#specifying-type-mappings[Specifying Type Mappings].
364450
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -513,6 +599,10 @@ AND SEARCH(t1, {
513599
----
514600
[
515601
{
602+
"meta": {
603+
"id": "hotel_17598",
604+
"score": 2.1256278997816835
605+
},
516606
"name": "Marina del Rey Marriott"
517607
}
518608
]
@@ -576,16 +666,19 @@ LIMIT 3;
576666
----
577667
[
578668
{
579-
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
580-
"name": "The Royal Victoria Hotel"
669+
"description": "370 guest rooms offering both water and mountain view.",
670+
"name": "Marina del Rey Marriott",
671+
"score": 2.1256278997816835
581672
},
582673
{
583-
"description": "370 guest rooms offering both water and mountain view.",
584-
"name": "Marina del Rey Marriott"
674+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
675+
"name": "Clwydian Holidays",
676+
"score": 1.6956645086702617
585677
},
586678
{
587-
"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.",
588-
"name": "The Glenforsa Hotel"
679+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
680+
"name": "The Royal Victoria Hotel",
681+
"score": 1.5030458987111712
589682
}
590683
]
591684
----

0 commit comments

Comments
 (0)