类型感知与错误"network error"的问题



我正在使用Reactjs,并且在将数据从Firestore同步到Typesense时遇到问题。我正在遵循这些文档,我所做的整个过程如下:https://typesense.org/docs/guide/firebase-full-text-search.html#step-1次运行类型感

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

  • 在我的Firebase项目中设置一个Cloud Firestore数据库。

  • 设置Typesense服务器(自托管(

  • 通过API设置Typesense集合。

  • 使用简单搜索参数查询数据

  • Instantsearch适配器适配器已安装并配置

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

这是代码:

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;

在实例化TypesenseInstantSearchAdapter以与对话时,您似乎已经配置了nodes

host: "127.0.0.1",
port: "8108",
protocol: "https"

但根据您在上面使用的配置,您的自托管服务器运行在:

host: "13.54.222.245",
port: "8108",
protocol: "http"

你看到的错误很可能是因为在127.0.0.1:8108上没有打开https的Typesense服务器

相关内容

最新更新