Javascript Algolia - 如何使用空搜索字符串启动新搜索?
Javascript Algolia - How to initiate a new search with an empty search string?
我的 Angular 应用程序中有一项功能,其中有一些存在于我的 Algolia 数据库中的可搜索项。问题是......它们无法通过任何字符串进行搜索。它们只能通过方面进行搜索。
问题是,当我 运行 我的初始 .search() 函数和一个空字符串 + 我的搜索 filters/facets 时,我得到一个返回列表,一切都很好。但是,当我再次转到 运行 函数来刷新列表时,它只会返回相同的结果并且实际上不会触发新请求,除非我更改其中一个 filters/facets。
有没有什么方法可以在我需要的时候强制执行搜索查询,而无需指定 "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
我的 Angular 应用程序中有一项功能,其中有一些存在于我的 Algolia 数据库中的可搜索项。问题是......它们无法通过任何字符串进行搜索。它们只能通过方面进行搜索。
问题是,当我 运行 我的初始 .search() 函数和一个空字符串 + 我的搜索 filters/facets 时,我得到一个返回列表,一切都很好。但是,当我再次转到 运行 函数来刷新列表时,它只会返回相同的结果并且实际上不会触发新请求,除非我更改其中一个 filters/facets。
有没有什么方法可以在我需要的时候强制执行搜索查询,而无需指定 "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