我從前端獲取 Algolia 搜索請求/查詢到我的 Lambda 函式中,然后執行請求并回傳結果。請求的格式是一個陣列,如
[
{
"indexName": "indexname",
"params": {
"query": "querytext",
"hitsPerPage": 7,
"maxValuesPerFacet": 3,
"page": 0,
"facets": [
"type"
],
"tagFilters": "",
"facetFilters": [
"account_id:1"
]
}
}
]
之后我使用他們的 API 客戶端進行搜索
const index = connectToIndex(ALGOLIA_APP,ALGOLIA_KEY,INDEX_NAME);
const results = await index.search(requests);
然后發生搜索查詢,但我得到 0 次點擊,當我console.log(results)的query欄位變形時
{
"hits": [],
"nbHits": 0,
"page": 0,
"nbPages": 0,
"hitsPerPage": 20,
"exhaustiveNbHits": true,
"exhaustiveTypo": true,
"query": "[{\"indexName\":\"indexname\",\"params\":{\"query\":\"querytext\",\"hitsPerPage\":7,\"maxValuesPerFacet\":3,\"page\":0,\"facets\":[\"type\"],\"tagFilters\":\"\",\"facetFilters\":[\"account_id:1\"]}}]",
"params": "query=[{"indexName":%indexname","params":{"query":"querytext","hitsPerPage":7,"maxValuesPerFacet":3,"page":0,"facets":["type"],"tagFilters":"","facetFilters":["account_id:1"]}}]",
"renderingContent": {},
"processingTimeMS": 1
}
但results應該如下所示(這是我console.log在快速服務器上得到的結果,我得到了所需的命中。注意它如何發送一個帶有results欄位的物件,并且query屬性只包含搜索到的文本)
{ results:
[ { hits: [Array],
nbHits: 20,
page: 0,
nbPages: 3,
hitsPerPage: 7,
facets: [Object],
exhaustiveFacetsCount: true,
exhaustiveNbHits: true,
exhaustiveTypo: true,
query: 'querytext',
params:
'query=querytext&hitsPerPage=7&maxValuesPerFacet=3&page=0&facets=["type"]&tagFilters=&facetFilters=["account_id:1"]',
index: 'indexname',
renderingContent: {},
processingTimeMS: 1 } ]
}
我的問題是為什么它console.log在 lambda 和 express 上有兩種不同的東西。我在相同的requests陣列中發送并在兩種情況下使用相同的 algolia API 搜索。
uj5u.com熱心網友回復:
好的,這是一個粗心的錯誤,
我connectToIndex回傳了一個 Algolia 索引
const connectToIndex = (appId,apiKey,index) => {
const client = algoliasearch(appId,apiKey);
return client.initIndex(index);
};
我已經使用index.search(requests)which 進行了搜索,這意味著client.initIndex().search(requests)
但是對于搜索,您不呼叫,initIndex而是直接呼叫searchclient
client.search(requests)
我在 express 中正確使用了它,并且在 lambda Github 問題中搞砸了
轉載請註明出處,本文鏈接:https://www.uj5u.com/caozuo/419817.html
標籤:
上一篇:在將大型JSON檔案轉換為JSON之前,如何使用AWSglueContext拆分/分塊?
下一篇:從CSV檔案填充雙指標矩陣
