gpt4 book ai didi

Javascript Algolia - 如何使用空搜索字符串启动新搜索?

转载 作者:行者123 更新时间:2023-12-03 03:24:34 26 4
gpt4 key购买 nike

我的 Angular 应用程序中有一项功能,其中我的 Algolia 数据库中存在一些可搜索的项目。问题是......它们不能通过任何字符串搜索。它们只能通过方面进行搜索。

问题是,当我使用空字符串+搜索过滤器/方面运行初始 .search() 函数时,我得到一个返回列表,一切都很好。然而,当我再次运行该函数来刷新列表时,它只会返回相同的结果,并且实际上永远不会触发新的请求,除非我更改其中一个过滤器/方面。

有什么方法可以在我想要的时候强制执行搜索查询,而不必指定"new"搜索条件?

这是我的搜索功能:

searchForAuditions() {

// Setup the filters/options
let options = {
highlightPreTag: '<span class="highlighted">',
highlightPostTag: '</span>',
hitsPerPage: 10,
};

// Add clause to make sure "is_deleted" is false
let isDeleted = ` is_deleted: "false"`;

let facets = `${isDeleted}`;

// Replace all trailing spaces and split it into an array
let facetWords = facets.replace(/\s+$/, '').split(" ");

// Remove trailing "AND"
if((facetWords[facetWords.length - 1] === "AND") || (facetWords[facetWords.length - 1] === "OR")) {
facetWords.splice(-1, 1);
facets = facetWords.join(' ');
}

if(facets) {
options['filters'] = facets;
}

this.auditionsIndex.search('', options).then(result => {
this.results = result.hits;
})
}

提前致谢!

最佳答案

来自 algolia JavaScript 客户端文档,

To avoid performing the same API calls twice search results will be stored in a cache that will be tied to your JavaScript client and index objects. Whenever a call for a specific query (and filters) is made, we store the results in a local cache. If you ever call the exact same query again, we read the results from the cache instead of doing an API call.

This is particularly useful when your users are deleting characters from their current query, to avoid useless API calls. Because it is stored as a simple JavaScript object in memory, the cache is automatically reset whenever you reload the page.

要解决此问题,您应该使用

index.clearCache()client.clearCache()

在此处了解有关内置缓存系统的更多信息。
https://github.com/algolia/algoliasearch-client-javascript#cache

关于Javascript Algolia - 如何使用空搜索字符串启动新搜索?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46389480/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com