【问题标题】:How to perform Full Text Search in Couchbase using Spring Data Repository如何使用 Spring Data Repository 在 Couchbase 中执行全文搜索
【发布时间】:2022-12-24 06:42:34
【问题描述】:

我已经为我的存储桶创建了一个全文搜索索引,我可以在 Web UI 中使用它并获得一些搜索结果。尽管如此,我还是找不到合适的示例来说明如何使用 Spring Data Couchbase 在现有存储库中创建存储库或方法来执行全文搜索。

这是我的索引定义:

{
  "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": {}
}

我只找到了这个简短的 Spring 文档 https://docs.spring.io/spring-data/couchbase/docs/current/reference/html/#:~:text=for%20more%20information.-,Full%20Text%20Search,-(FTS),他们建议使用 Cluster 类。

首先,如果可能的话,我想使用 Spring 存储库而不是此类。如果不是,我如何转换从返回的SearchResult

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

进入我的实体对象列表?

【问题讨论】:

    标签: java couchbase spring-data-couchbase


    【解决方案1】:

    spring data couchbase 存储库中没有 FTS 集成。

    使用 8.3 对象转换进行对象映射。 https://docs.spring.io/spring-data/couchbase/docs/4.4.0/reference/html/#couchbase.transactions

    一行中有(曾经?)错别字。需要使用 target.export() 而不是 target.getContent()

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

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-06-29
      • 2018-03-11
      • 2018-09-05
      相关资源
      最近更新 更多