Algolia:查询从属索引以获得按日期排序功能排序的最佳方式
Algolia: Best way to query slave index to get sort by date ranking functionality
我有一个数据集,我想动态地按日期(升序和降序)排序。我通读了文档并按照指示创建了我的主索引的从属索引,其中最高排名值是我的 'date' 按 DESC 排序。日期采用正确的整数和 unix 时间戳格式。
我的问题是如何使用前端 Javascript Algolia API?
即时查询这个新索引
现在,我的代码如下所示:
this.client = algoliasearch("xxxx", "xxxxx");
this.index = this.client.initIndex('master_index');
this.index.search(
this.query, {
hitsPerPage: 10,
page: this.pagination,
facets: '*',
facetFilters: facetArray
},
function(error, results) {
// do stuff
}.bind(this));
我尝试做的是将 initIndex 更改为使用我的从属索引,这确实有效......但我认为如果我每次都需要重新初始化索引,这会很慢且效率低下用户只想按日期排序。不是有一个参数可以插入查询以按日期排序吗?
另外,我的第二个问题是,即使我将索引更改为从索引,它也只是按降序排列。我怎样才能让它也按升序排序?
我真的不想创建另一个从属索引只是为了按日期升序排序,因为我有数千行并且已经接近超过我的记录限制。肯定还有别的办法吗?
谢谢!
What I've tried doing is to just change the initIndex to use my slave index instead and this does work...but I'm thinking that this is slow and inefficient if I need to reinitialize the index every time the user just wants to sort by date. Isn't there a parameter instead that I can insert in the query to sort by date?
您应该将要排序的所有索引存储在 this
对象的不同属性中:
this.indices = {
mostRelevant: this.client.initIndex('master_index'),
desc: this.client.initIndex('slave_desc')
};
然后你可以使用this.indices.mostRelevant.search()或this.indices.desc.search()。
这样做不是性能问题。
另请参阅创建即时搜索体验的专用库:https://community.algolia.com/instantsearch.js/
Also, my second question is that even when I change the index to the slave index, it only sorts by descending. How can I have it sort by ascending as well?
I really do not want to create ANOTHER slave index just to sort by ascending date since I have many thousands of rows and am already close to exceeding my record limit. Surely there must be another way here?
这是在 Algolia 中进行排序的唯一正确方法。这是设计使 Algolia 如此之快的原因,也是目前唯一的方法。
我有一个数据集,我想动态地按日期(升序和降序)排序。我通读了文档并按照指示创建了我的主索引的从属索引,其中最高排名值是我的 'date' 按 DESC 排序。日期采用正确的整数和 unix 时间戳格式。
我的问题是如何使用前端 Javascript Algolia API?
即时查询这个新索引现在,我的代码如下所示:
this.client = algoliasearch("xxxx", "xxxxx");
this.index = this.client.initIndex('master_index');
this.index.search(
this.query, {
hitsPerPage: 10,
page: this.pagination,
facets: '*',
facetFilters: facetArray
},
function(error, results) {
// do stuff
}.bind(this));
我尝试做的是将 initIndex 更改为使用我的从属索引,这确实有效......但我认为如果我每次都需要重新初始化索引,这会很慢且效率低下用户只想按日期排序。不是有一个参数可以插入查询以按日期排序吗?
另外,我的第二个问题是,即使我将索引更改为从索引,它也只是按降序排列。我怎样才能让它也按升序排序?
我真的不想创建另一个从属索引只是为了按日期升序排序,因为我有数千行并且已经接近超过我的记录限制。肯定还有别的办法吗?
谢谢!
What I've tried doing is to just change the initIndex to use my slave index instead and this does work...but I'm thinking that this is slow and inefficient if I need to reinitialize the index every time the user just wants to sort by date. Isn't there a parameter instead that I can insert in the query to sort by date?
您应该将要排序的所有索引存储在 this
对象的不同属性中:
this.indices = {
mostRelevant: this.client.initIndex('master_index'),
desc: this.client.initIndex('slave_desc')
};
然后你可以使用this.indices.mostRelevant.search()或this.indices.desc.search()。
这样做不是性能问题。
另请参阅创建即时搜索体验的专用库:https://community.algolia.com/instantsearch.js/
Also, my second question is that even when I change the index to the slave index, it only sorts by descending. How can I have it sort by ascending as well?
I really do not want to create ANOTHER slave index just to sort by ascending date since I have many thousands of rows and am already close to exceeding my record limit. Surely there must be another way here?
这是在 Algolia 中进行排序的唯一正确方法。这是设计使 Algolia 如此之快的原因,也是目前唯一的方法。