首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >“网络错误”与“类型错误”问题

“网络错误”与“类型错误”问题
EN

Stack Overflow用户
提问于 2022-01-11 03:12:29
回答 1查看 476关注 0票数 1

我正在使用Reactjs,并且在从Firestore到Typesense的同步数据方面有问题。我正在跟踪这些文档,我所做的整个过程就是:https://typesense.org/docs/guide/firebase-full-text-search.html#step-1-run-typesense

此外,下面是我根据上面的链接为我的项目所做的配置。

  • 在我的Firebase项目中设置一个数据库。
  • 设置一个Typesense服务器(自托管)
  • 通过API设置一个Typesense集合。
  • 使用简单的搜索参数查询数据
  • Instantsearch适配器已经安装和配置

问题:它不会呈现数据,并且有以下错误:类型-网络错误

下面是代码:

代码语言:javascript
复制
import "./App.css";
import { InstantSearch, SearchBox, Hits, Stats } from "react-instantsearch-dom";
import TypesenseInstantSearchAdapter from "typesense-instantsearch-adapter";
import Typesense from "typesense";

const client = new Typesense.Client({
  nodes: [
    {
      host: "13.54.222.245", //ip address of the typesense server i have setup on AWS Lightsail
      port: "8108",
      protocol: "http",
    },
  ],
  apiKey: "admin_apikey",
  connectionTimeoutSeconds: 2,
});

// creating a collection
const eventData = {
  name: "events",
  fields: [
    { name: "eventName", type: "string" },
    { name: "eventInfo", type: "string[]" },
  ],
};
client
  .collections()
  .create(eventData)
  .then(function (data) {
    console.log(data);
  });

// query the data using search parameters
const search = {
  q: "events",
  query_by: "eventName",
};

client
  .collections("eventData")
  .documents()
  .search(search)
  .then(function (searchResults) {
    console.log(searchResults);
  });

// search interface for the client side
const typesenseInstantsearchAdapter = new TypesenseInstantSearchAdapter({
  server: {
    apiKey: "admin_apikey",
    nodes: [
      {
        host: "127.0.0.1",
        port: "8108",
        protocol: "https",
      },
    ],
  },
  additionalSearchParameters: {
    queryBy: "eventName, eventInfo",
  },
});
const searchClient = typesenseInstantsearchAdapter.searchClient;

function SearchInterface() {
  const Hit = ({ hit }) => (
    <section class="main">
      <div class="card-container">
        <div class="card-header">
          <h4>{hit.eventName}</h4>
          <p>{hit.eventInfo}</p>
        </div>
        <hr />
      </div>
    </section>
  );

  return (
    <InstantSearch searchClient={searchClient} indexName="eventData">
      <SearchBox />
      <Stats />
      <Hits hitComponent={Hit} />
    </InstantSearch>
  );
}
export default SearchInterface;
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2022-01-11 04:22:55

在实例化要与之交谈的nodes时,您似乎已经配置了TypesenseInstantSearchAdapter

代码语言:javascript
复制
host: "127.0.0.1",
port: "8108",
protocol: "https"

但是,基于上面使用的配置,您的自托管服务器运行于:

代码语言:javascript
复制
host: "13.54.222.245",
port: "8108",
protocol: "http"

您所看到的错误很可能是因为没有Typesense服务器在127.0.0.1:8108上运行,并且打开了https。

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/70661202

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档