我正在使用 Reactjs,并且在將資料從 Firestore 同步到 Typesense 時遇到問題。我正在關注這個檔案,我所做的整個程序都在這里:https : //typesense.org/docs/guide/firebase-full-text-search.html#step-1-run-typesense
此外,以下是我根據上面的鏈接為我的專案所做的配置。
在我的 Firebase 專案中設定 Cloud Firestore 資料庫。
設定 Typesense 服務器(自托管)
通過 API 設定 Typesense 集合。
使用簡單的搜索引數查詢資料
Instantsearch Adapter 配接器已安裝并配置
問題:它不會呈現資料并且出現此錯誤:Typesense - Network error
這是代碼:
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;
uj5u.com熱心網友回復:
看起來你已經nodes在實體化時TypesenseInstantSearchAdapter進行了配置以與之交談
host: "127.0.0.1",
port: "8108",
protocol: "https"
但是根據您在上面使用的配置,您的自托管服務器運行在:
host: "13.54.222.245",
port: "8108",
protocol: "http"
您最有可能看到的錯誤是因為沒有 Typesense 服務器在 127.0.0.1:8108 上運行并打開了 https。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/408745.html
標籤:
