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
@@ -350,8 +396,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
350
396
----
351
397
352
398
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
+
----
355
467
356
468
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
469
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -506,6 +618,10 @@ AND SEARCH(t1, {
506
618
----
507
619
[
508
620
{
621
+
"meta": {
622
+
"id": "hotel_17598",
623
+
"score": 2.1256278997816835
624
+
},
509
625
"name": "Marina del Rey Marriott"
510
626
}
511
627
]
@@ -569,16 +685,19 @@ LIMIT 3;
569
685
----
570
686
[
571
687
{
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
574
691
},
575
692
{
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
578
696
},
579
697
{
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
582
701
}
583
702
]
584
703
----
@@ -682,4 +801,4 @@ WHERE reviews.content LIKE "%travel%";
682
801
SELECT META().id
683
802
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
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.
14
14
For more information, refer to xref:fts:fts-quickstart-guide.adoc#preparing-for-full-text-searches[Preparing for Full Text Searches].
15
15
16
16
[NOTE]
17
17
--
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
+
19
65
--
20
66
21
67
[float]
@@ -334,7 +380,7 @@ As an alternative, you could limit the number of results and order them using th
334
380
[source,n1ql]
335
381
----
336
382
SELECT META(t1).id
337
-
FROM `travel-sample`.inventory.hotel AS t1
383
+
FROM `travel-sample` AS t1
338
384
WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
339
385
----
340
386
@@ -358,7 +404,74 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
358
404
----
359
405
360
406
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
+
----
362
475
363
476
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].
364
477
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
@@ -513,6 +626,10 @@ AND SEARCH(t1, {
513
626
----
514
627
[
515
628
{
629
+
"meta": {
630
+
"id": "hotel_17598",
631
+
"score": 2.1256278997816835
632
+
},
516
633
"name": "Marina del Rey Marriott"
517
634
}
518
635
]
@@ -576,16 +693,19 @@ LIMIT 3;
576
693
----
577
694
[
578
695
{
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
581
699
},
582
700
{
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
585
704
},
586
705
{
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",
0 commit comments