我的Ionic 2应用程序中有一些搜索功能,除了搜索字符串外,还需要能够将搜索过滤器添加到搜索中。我有搜索字符串片工作,但我不知道如何传递值数组来检查我的Algolia指数中的特定数组。如何查询Algolia利用搜索字符串和项目数组来检查?
这里是我的功能:
searchForUsers(filters?) {
let options = {
attributesToHighlight: ['display_name', 'instruments'],
highlightPreTag: '<span class="highlighted">',
highlightPostTag: '</span>',
attributesToRetrieve: [
"_geoloc",
"display_name",
"genres",
"instruments",
"objectID",
"playing_level",
"profile_photo",
],
};
// If there are any filters enabled?
if(filters) {
options['aroundLatLng'] = `${this.geoloc.lat},${this.geoloc.lng}`;
options['aroundRadius'] = this._utilities.milesToMeters(this.distance);
}
this.usersIndex.search(this.searchTerm, options)
.then((data) => {
this.results = data.hits;
})
.catch((error) => {
console.log(error);
});
}
如果我想下面的筛选器添加到我的搜索,我怎么会去这样做?
["Blues", "Rock", "Alternative"]
// < - 这些会在Algolia检查genres
。 ["Guitar", "Drums", "Piano"]
// < - 这些将在Algolia检查instruments
。
^这两个数组是额外的过滤器,它会限制返回的结果,就像您在数千个不同的搜索组件中看到的那样。虽然我无法弄清楚这一点。任何想法?
提前谢谢!
这是完美的,正是我所需要的。 Thankyou –
没问题。很高兴这是你需要的。快乐编码! :) –