简体   繁体   中英

How to perform Full Text Search in Couchbase using Spring Data Repository

I have created a full-text search index for my bucket and I am able to use it in web UI and get some search results. Still, I can't find an appropriate example of how to create a repository or method in the existing repository using Spring Data Couchbase for performing a full-text search.

Here is my index definition:

{
  "type": "fulltext-index",
  "name": "FTI_Users",
  "uuid": "48316628ed720269",
  "sourceType": "gocbcore",
  "sourceName": "Users",
  "sourceUUID": "d8a535cb7b46f6b4f85b24bc0887e740",
  "planParams": {
    "maxPartitionsPerPIndex": 1024,
    "indexPartitions": 1
  },
  "params": {
    "doc_config": {
      "docid_prefix_delim": "",
      "docid_regexp": "",
      "mode": "type_field",
      "type_field": "type"
    },
    "mapping": {
      "analysis": {},
      "default_analyzer": "standard",
      "default_datetime_parser": "dateTimeOptional",
      "default_field": "_all",
      "default_mapping": {
        "dynamic": true,
        "enabled": true
      },
      "default_type": "_default",
      "docvalues_dynamic": false,
      "index_dynamic": true,
      "store_dynamic": true,
      "type_field": "_type"
    },
    "store": {
      "indexType": "scorch",
      "segmentVersion": 15
    }
  },
  "sourceParams": {}
}

All I found is this short Spring documentation https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#:~:text=for%20more%20information.-,Full%20Text%20Search,-(FTS) where they suggest using Cluster class.

First of all, I would like to use the Spring repository instead of this class if it's possible. If not, how do I convert SearchResult that returns from

cluster.searchQuery("FTI_Users", SearchQuery.queryString(query))

into a list of my entity objects?

There is no integration for FTS in spring data couchbase repositories.

Use 8.3 Object Conversion for object mapping. https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#couchbase.transactions

There is (was?) a typo in one line. target.export() needs to be used instead of target.getContent()

ctx.insert(couchbaseClientFactory.getDefaultCollection(), target.getId(), target.export());

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM