You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
@@ -5,11 +5,57 @@ Search functions enable you to use full text search queries directly within a N1
5
5
== Prerequisites
6
6
7
7
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.
9
9
10
10
[NOTE]
11
11
--
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
+
13
59
--
14
60
15
61
=== Authorization
@@ -203,33 +249,29 @@ The following queries are equivalent:
203
249
[source,n1ql]
204
250
----
205
251
SELECT META(t1).id
206
-
FROM `travel-sample`.inventory.airline AS t1
252
+
FROM `travel-sample`.inventory.hotel AS t1
207
253
WHERE SEARCH(t1.country, "+United +States");
208
254
----
209
255
210
256
[source,n1ql]
211
257
----
212
258
SELECT META(t1).id
213
-
FROM `travel-sample`.inventory.airline AS t1
259
+
FROM `travel-sample`.inventory.hotel AS t1
214
260
WHERE SEARCH(t1, "country:\"United States\"");
215
261
----
216
262
217
263
.Results
218
264
[source,json]
219
265
----
220
266
[
221
-
222
-
{
223
-
"id": "airline_10"
224
-
},
225
267
{
226
-
"id": "airline_10123"
268
+
"id": "hotel_26215"
227
269
},
228
270
{
229
-
"id": "airline_10226"
271
+
"id": "hotel_7396"
230
272
},
231
273
{
232
-
"id": "airline_10748"
274
+
"id": "hotel_32177"
233
275
},
234
276
...
235
277
]
@@ -350,8 +392,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
350
392
----
351
393
352
394
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
+
----
355
463
356
464
For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
357
465
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +614,10 @@ AND SEARCH(t1, {
506
614
----
507
615
[
508
616
{
617
+
"meta": {
618
+
"id": "hotel_17598",
619
+
"score": 2.1256278997816835
620
+
},
509
621
"name": "Marina del Rey Marriott"
510
622
}
511
623
]
@@ -569,16 +681,19 @@ LIMIT 3;
569
681
----
570
682
[
571
683
{
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
574
687
},
575
688
{
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
578
692
},
579
693
{
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
582
697
}
583
698
]
584
699
----
@@ -682,4 +797,4 @@ WHERE reviews.content LIKE "%travel%";
682
797
SELECT META().id
683
798
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
0 commit comments