Skip to content

DOC-9450: Update SEARCH_META(..) instructions and examples #2468

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 3 commits into from
Feb 24, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion modules/fts/pages/fts-quickstart-guide.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -47,5 +47,4 @@ Refer to xref:n1ql:n1ql-language-reference/searchfun.adoc[Search Functions] for
== Establishing Demonstration Indexes

The Java SDK code-example provided in xref:java-sdk:howtos:full-text-searching-with-sdk.adoc[Searching from the SDK] contains multiple demonstration calls — each featuring a different query-combination — and makes use of three different index-definitions, related to the `travel-sample` bucket: for the code example to run successfully, the three indexes must be appropriately pre-established.
//The definitions are provided in xref:fts-demonstration-indexes.adoc[Demonstration Indexes].
Instructions on how to use the Couchbase REST API to establish the definitions refer to xref:fts-creating-index-with-rest-api.adoc[Creating Index with REST API].
132 changes: 112 additions & 20 deletions modules/fts/pages/fts-searching-from-N1QL.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,57 @@ Search functions enable you to use full text search queries directly within a N1
== Prerequisites

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

[NOTE]
--
The examples in this page all assume that demonstration full text indexes have been created.
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise ..
The examples in this page assume that you have a full text search index created with this definition, unless specified otherwise.

[source,json]
----
{
"name": "travel-sample-inventory-hotels",
"type": "fulltext-index",
"params": {
"doc_config": {
"mode": "scope.collection.type_field",
"type_field": "type"
},
"mapping": {
"default_analyzer": "standard",
"default_datetime_parser": "dateTimeOptional",
"default_field": "_all",
"default_mapping": {
"dynamic": true,
"enabled": false
},
"default_type": "_default",
"docvalues_dynamic": false,
"index_dynamic": true,
"store_dynamic": false,
"type_field": "_type",
"types": {
"inventory.hotel": {
"dynamic": true,
"enabled": true
}
}
},
"store": {
"indexType": "scorch",
"segmentVersion": 15
}
},
"sourceType": "gocbcore",
"sourceName": "travel-sample",
"sourceUUID": "",
"sourceParams": {},
"planParams": {
"indexPartitions": 1
},
"uuid": ""
}
----

--

=== Authorization
Expand Down Expand Up @@ -203,33 +249,29 @@ The following queries are equivalent:
[source,n1ql]
----
SELECT META(t1).id
FROM `travel-sample`.inventory.airline AS t1
FROM `travel-sample`.inventory.hotel AS t1
WHERE SEARCH(t1.country, "+United +States");
----

[source,n1ql]
----
SELECT META(t1).id
FROM `travel-sample`.inventory.airline AS t1
FROM `travel-sample`.inventory.hotel AS t1
WHERE SEARCH(t1, "country:\"United States\"");
----

.Results
[source,json]
----
[

{
"id": "airline_10"
"id": "hotel_26215"
},
{
"id": "airline_10123"
"id": "hotel_7396"
},
{
"id": "airline_10226"
},
{
"id": "airline_10748"
"id": "hotel_32177"
},
...
]
Expand Down Expand Up @@ -350,8 +392,51 @@ WHERE t1.type = "hotel" AND SEARCH(t1.description, "amazing");
----

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.

//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".
The above query uses the following index definition ..
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
The above query uses the following index definition ..
The above query uses the following index definition:

[source,json]
----
{
"name": "travel-sample-hotels",
"type": "fulltext-index",
"params": {
"doc_config": {
"mode": "type_field",
"type_field": "type"
},
"mapping": {
"default_analyzer": "standard",
"default_datetime_parser": "dateTimeOptional",
"default_field": "_all",
"default_mapping": {
"dynamic": true,
"enabled": false
},
"default_type": "_default",
"index_dynamic": true,
"store_dynamic": true,
"type_field": "type",
"types": {
"hotel": {
"dynamic": true,
"enabled": true
}
}
},
"store": {
"indexType": "scorch",
"segmentVersion": 15
}
},
"sourceType": "gocbcore",
"sourceName": "travel-sample",
"sourceUUID": "",
"sourceParams": {},
"planParams": {
"indexPartitions": 1
},
"uuid": ""
}
----

For more information on defining custom type mappings within the full text search index, refer to xref:fts:fts-type-mappings.adoc[Type Mappings].
Note that for N1QL queries, only full text search indexes with one type mapping are searchable.
Expand Down Expand Up @@ -506,6 +591,10 @@ AND SEARCH(t1, {
----
[
{
"meta": {
"id": "hotel_17598",
"score": 2.1256278997816835
},
"name": "Marina del Rey Marriott"
}
]
Expand Down Expand Up @@ -569,16 +658,19 @@ LIMIT 3;
----
[
{
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
"name": "The Royal Victoria Hotel"
"description": "370 guest rooms offering both water and mountain view.",
"name": "Marina del Rey Marriott",
"score": 2.1256278997816835
},
{
"description": "370 guest rooms offering both water and mountain view.",
"name": "Marina del Rey Marriott"
"description": "Log cabin glamping in a rural setting with panoramic views toward the Clwydian Mountain Range.",
"name": "Clwydian Holidays",
"score": 1.6956645086702617
},
{
"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.",
"name": "The Glenforsa Hotel"
"description": "3 Star Hotel next to the Mountain Railway terminus and set in 30 acres of grounds which include Dolbadarn Castle",
"name": "The Royal Victoria Hotel",
"score": 1.5030458987111712
}
]
----
Expand Down Expand Up @@ -682,4 +774,4 @@ WHERE reviews.content LIKE "%travel%";
SELECT META().id
FROM `travel-sample`.`inventory`.`hotel` t USE INDEX(USING FTS)
WHERE content LIKE "%travel%";
----
----
57 changes: 55 additions & 2 deletions modules/fts/pages/fts-supported-queries-geo-spatial.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -232,8 +232,61 @@ For initial experimentation with geospatial querying, the `geo` field of documen
[#fts_geopoint_definition]
image::fts-geopoint-definition.png[,620,align=left]

The index so created can also be specified by means of the Couchbase REST API.
See xref:fts-demonstration-indexes.adoc[Demonstration Indexes] for the body of the index to be used, and see xref:fts-creating-index-with-rest-api.adoc[Index Creation with the REST API] for information on using the REST syntax.
The following query examples in this page will require the following index definition ..

[source,json]
----
{
"type": "fulltext-index",
"name": "geoIndex",
"uuid": "",
"sourceType": "gocbcore",
"sourceName": "travel-sample",
"sourceUUID": "",
"planParams": {
"indexPartitions": 1
},
"params": {
"doc_config": {
"mode": "type_field",
"type_field": "type"
},
"mapping": {
"default_analyzer": "standard",
"default_datetime_parser": "dateTimeOptional",
"default_field": "_all",
"default_mapping": {
"dynamic": true,
"enabled": true,
"properties": {
"geo": {
"dynamic": false,
"enabled": true,
"fields": [
{
"include_in_all": true,
"include_term_vectors": true,
"index": true,
"name": "geo",
"store": true,
"type": "geopoint"
}
]
}
}
},
"default_type": "_default",
"index_dynamic": true,
"store_dynamic": false
},
"store": {
"indexType": "scorch",
"segmentVersion": 15
}
},
"sourceParams": {}
}
----

[#creating_geospatial_rest_query_radius_based]
=== Creating a Query: Radius-Based
Expand Down
Loading