Typesense

Posted newhappy98

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Typesense相关的知识,希望对你有一定的参考价值。

Usage

cat > docker-compose.yml <<-\'EOF\'
# https://hub.docker.com/r/typesense/typesense
# Port: 8108
version: "3"

services:
  typesense:
    image: typesense/typesense:0.24.0
    command: \'--data-dir /data/ --api-key=password --enable-cors\'
    network_mode: host
    restart: always
    volumes:
      - $PWD/typesense/data/:/data/

EOF
# https://typesense.org/docs/guide/docsearch.html#step-1-set-up-docsearch-scraper
docker run -it \\
    --env "CONFIG=$(cat ./docusaurus-2.json | jq -r tostring)" \\
    --env-file=.env \\
    typesense/docsearch-scraper

docusaurus-2.json


    "index_name": "docusaurus-2",
    "start_urls": [
        "https://docusaurus.io/"
    ],
    "sitemap_urls": [
        "https://docusaurus.io/sitemap.xml"
    ],
    "sitemap_alternate_links": true,
    "stop_urls": [
        "/tests"
    ],
    "selectors": 
        "lvl0": 
            "selector": "(//ul[contains(@class,\'menu__list\')]//a[contains(@class, \'menu__link menu__link--sublist menu__link--active\')]/text() | //nav[contains(@class, \'navbar\')]//a[contains(@class, \'navbar__link--active\')]/text())[last()]",
            "type": "xpath",
            "global": true,
            "default_value": "Documentation"
        ,
        "lvl1": "header h1",
        "lvl2": "article h2",
        "lvl3": "article h3",
        "lvl4": "article h4",
        "lvl5": "article h5, article td:first-child",
        "lvl6": "article h6",
        "text": "article p, article li, article td:last-child"
    ,
    "strip_chars": " .,;:#",
    "custom_settings": 
        "separatorsToIndex": "_",
        "attributesForFaceting": [
            "language",
            "version",
            "type",
            "docusaurus_tag"
        ],
        "attributesToRetrieve": [
            "hierarchy",
            "content",
            "anchor",
            "url",
            "url_without_anchor",
            "type"
        ]
    ,
    "conversation_id": [
        "833762294"
    ],
    "nb_hits": 46250


如何以typesense存储带有键值的数组

【中文标题】如何以typesense存储带有键值的数组【英文标题】:How to store array with key value in typesense 【发布时间】:2021-10-26 12:47:21 【问题描述】:

我是类型感的新手, 我在 typeense 中为 geoloc 创建了一个模式。

架构

curl "http://localhost:8108/collections" \
        -X POST \
        -H "Content-Type: application/json" \
        -H "X-TYPESENSE-API-KEY: xyz" \
        -d '
              "name": "demo",
              "fields": [
                "name": "name", "type": "string" ,
                "name": "city", "type": "string" ,
                "name": "country", "type": "string" ,
                "name": "iata_code", "type": "string" ,
                "name": "_geoloc", "type": "string[]" , "facet": true ,
                "name": "links_count", "type": "int32" ,
                "name": "objectID", "type": "string" 
              ]
            '

我尝试存储

curl "http://localhost:8108/collections/airports4/documents/import" \
        -X POST \
        -H "Content-Type: application/json" \
        -H "X-TYPESENSE-API-KEY: xyz" \
        -d '
           "name": "Kalemie","city": "Kalemie","country": "Congo (Kinshasa)","iata_code": "FMI","_geoloc":  "lat" : -5.875556 ,  "long" : 29.25 ,"links_count":1,"objectID": "1040"'

但它返回一个错误

"code":400,"document":"","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 2: syntax error while parsing object key - unexpected end of input; expected string literal","success":false
"code":400,"document":"\t\"name\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"city\": \"Kalemie\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 8: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"country\": \""Congo (Kinshasa)\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 11: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"iata_code\": \"FMI\",","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 13: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"_geoloc\" : [\"lat\":-5.875556 , \"lng\": 29.25 ],","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"links_count\": 1,","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 15: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"\t\"objectID\": \"1040\"","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 12: syntax error while parsing value - unexpected ':'; expected end of input","success":false
"code":400,"document":"","error":"Bad JSON: [json.exception.parse_error.101] parse error at line 1, column 1: syntax error while parsing value - unexpected ''; expected '[', '', or a literal","success":false

我不知道如何用 lat long 存储 _geoloc。

【问题讨论】:

【参考方案1】:

您必须使用geopoint 类型的字段。

这是文档中的一个示例:https://typesense.org/docs/0.21.0/api/documents.html#geosearch

【讨论】:

感谢您帮助@jeffreyveon。现在它可以正常工作了。

以上是关于Typesense的主要内容,如果未能解决你的问题,请参考以下文章