Skip to content

Commit d4bd35e

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

File tree

2 files changed

+260
-21
lines changed

2 files changed

+260
-21
lines changed

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

Lines changed: 130 additions & 11 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
@@ -350,8 +396,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
350396
----
351397
352398
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".
399+
The above query uses the following index definition ..
400+
[source,json]
401+
----
402+
{
403+
"name": "travel-sample-index-hotel-description",
404+
"type": "fulltext-index",
405+
"params": {
406+
"doc_config": {
407+
"mode": "type_field",
408+
"type_field": "type"
409+
},
410+
"mapping": {
411+
"analysis": {
412+
"analyzers": {
413+
"myUnicodeAnalyzer": {
414+
"tokenizer": "unicode",
415+
"type": "custom"
416+
}
417+
}
418+
},
419+
"default_analyzer": "standard",
420+
"default_datetime_parser": "dateTimeOptional",
421+
"default_field": "_all",
422+
"default_mapping": {
423+
"dynamic": true,
424+
"enabled": false
425+
},
426+
"default_type": "_default",
427+
"index_dynamic": true,
428+
"store_dynamic": true,
429+
"type_field": "type",
430+
"types": {
431+
"hotel": {
432+
"dynamic": false,
433+
"enabled": true,
434+
"properties": {
435+
"description": {
436+
"enabled": true,
437+
"dynamic": false,
438+
"fields": [
439+
{
440+
"include_in_all": true,
441+
"include_term_vectors": true,
442+
"index": true,
443+
"name": "description",
444+
"store": true,
445+
"type": "text"
446+
}
447+
]
448+
}
449+
}
450+
}
451+
}
452+
},
453+
"store": {
454+
"indexType": "scorch"
455+
}
456+
},
457+
"sourceType": "couchbase",
458+
"sourceName": "travel-sample",
459+
"sourceUUID": "",
460+
"sourceParams": {},
461+
"planParams": {
462+
"indexPartitions": 1
463+
},
464+
"uuid": ""
465+
}
466+
----
355467
356468
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
357469
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +618,10 @@ AND SEARCH(t1, {
506618
----
507619
[
508620
{
621+
"meta": {
622+
"id": "hotel_17598",
623+
"score": 2.1256278997816835
624+
},
509625
"name": "Marina del Rey Marriott"
510626
}
511627
]
@@ -569,16 +685,19 @@ LIMIT 3;
569685
----
570686
[
571687
{
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"
688+
"description": "370 guest rooms offering both water and mountain view.",
689+
"name": "Marina del Rey Marriott",
690+
"score": 2.1256278997816835
574691
},
575692
{
576-
"description": "370 guest rooms offering both water and mountain view.",
577-
"name": "Marina del Rey Marriott"
693+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
694+
"name": "Clwydian Holidays",
695+
"score": 1.6956645086702617
578696
},
579697
{
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"
698+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
699+
"name": "The Royal Victoria Hotel",
700+
"score": 1.5030458987111712
582701
}
583702
]
584703
----
@@ -682,4 +801,4 @@ WHERE reviews.content LIKE "%travel%";
682801
SELECT META().id
683802
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
684803
WHERE content LIKE "%travel%";
685-
----
804+
----

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

Lines changed: 130 additions & 10 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]
@@ -334,7 +380,7 @@ As an alternative, you could limit the number of results and order them using th
334380
[source,n1ql]
335381
----
336382
SELECT META(t1).id
337-
FROM `travel-sample`.inventory.hotel AS t1
383+
FROM `travel-sample` AS t1
338384
WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
339385
----
340386
@@ -358,7 +404,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
358404
----
359405
360406
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".
407+
The above query uses the following index definition ..
408+
[source,json]
409+
----
410+
{
411+
"name": "travel-sample-index-hotel-description",
412+
"type": "fulltext-index",
413+
"params": {
414+
"doc_config": {
415+
"mode": "type_field",
416+
"type_field": "type"
417+
},
418+
"mapping": {
419+
"analysis": {
420+
"analyzers": {
421+
"myUnicodeAnalyzer": {
422+
"tokenizer": "unicode",
423+
"type": "custom"
424+
}
425+
}
426+
},
427+
"default_analyzer": "standard",
428+
"default_datetime_parser": "dateTimeOptional",
429+
"default_field": "_all",
430+
"default_mapping": {
431+
"dynamic": true,
432+
"enabled": false
433+
},
434+
"default_type": "_default",
435+
"index_dynamic": true,
436+
"store_dynamic": true,
437+
"type_field": "type",
438+
"types": {
439+
"hotel": {
440+
"dynamic": false,
441+
"enabled": true,
442+
"properties": {
443+
"description": {
444+
"enabled": true,
445+
"dynamic": false,
446+
"fields": [
447+
{
448+
"include_in_all": true,
449+
"include_term_vectors": true,
450+
"index": true,
451+
"name": "description",
452+
"store": true,
453+
"type": "text"
454+
}
455+
]
456+
}
457+
}
458+
}
459+
}
460+
},
461+
"store": {
462+
"indexType": "scorch"
463+
}
464+
},
465+
"sourceType": "couchbase",
466+
"sourceName": "travel-sample",
467+
"sourceUUID": "",
468+
"sourceParams": {},
469+
"planParams": {
470+
"indexPartitions": 1
471+
},
472+
"uuid": ""
473+
}
474+
----
362475
363476
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].
364477
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -513,6 +626,10 @@ AND SEARCH(t1, {
513626
----
514627
[
515628
{
629+
"meta": {
630+
"id": "hotel_17598",
631+
"score": 2.1256278997816835
632+
},
516633
"name": "Marina del Rey Marriott"
517634
}
518635
]
@@ -576,16 +693,19 @@ LIMIT 3;
576693
----
577694
[
578695
{
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"
696+
"description": "370 guest rooms offering both water and mountain view.",
697+
"name": "Marina del Rey Marriott",
698+
"score": 2.1256278997816835
581699
},
582700
{
583-
"description": "370 guest rooms offering both water and mountain view.",
584-
"name": "Marina del Rey Marriott"
701+
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
702+
"name": "Clwydian Holidays",
703+
"score": 1.6956645086702617
585704
},
586705
{
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"
706+
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
707+
"name": "The Royal Victoria Hotel",
708+
"score": 1.5030458987111712
589709
}
590710
]
591711
----

0 commit comments

Comments
 (0)