是否可以随机排序,并查询字段是否存在? [英] Is it possible to sort randomly, and to query on field if it exists?

查看:134
本文介绍了是否可以随机排序,并查询字段是否存在?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在Algolia上,我正在尝试随机排序......是否可能?

我也尝试查询字段是否不存在。

<
c $ c> facets 我尝试了类似 my_attribut:null ......但我不确定是否可能。

On Algolia, I'm trying to sort randomly ... Is it possible?
I also try to query if a field doesn't exists.
With facets I tried something like my_attribut:null ... but I'm not sure if it's possible.

你能帮助我吗?

谢谢

推荐答案

随机排序顺序



尽管在排名公式中有一个随机顺序可能是有意义的,但它与引擎的方式不相容已建成。通过关注速度+针对性,Algolia的引擎做了一些权衡,因为它在索引时预先计算了大量信息,因此无法在每个查询中随机化。此外,它会打破任何分页。

Random sort order

Even though it could possibly make sense to have a random order in the ranking formula, it is incompatible with the way the engine has been built. By focusing on speed + pertinence, Algolia's engine has made some tradeoffs since it is precalculating a lot of information at indexing time making it impossible to randomize at each query. Furthermore, it would break any pagination.

但是,您可以在收到结果后随机播放,这样可以让您拥有正确的分页。

However, you can shuffle the results after receiving them, which would allow you to have a correct pagination.

使用此问题的 shuffle 方法如何将数组洗牌?


function shuffle (o){
  for(var j, x, i = o.length; i; j = Math.floor(Math.random() * i), x = o[--i], o[i] = o[j], o[j] = x);
  return o;
}


使用 JavaScript客户端

index.search('something', function searchDone(err, content) {
  content.hits = shuffle(content.hits);
  // Use them
});

使用 JavaScript助手

helper.on('result', function (data){
  data.hits = shuffle(data.hits);
  // Use them
});



查询不存在的属性



使用Algolia进行此类操作的唯一方法是将您认为的值推送为 null (例如 null 字符串或 -1 表示正整数。)

Querying a non-existing attribute

The only way to do such a thing with Algolia is to push a value that you'll consider as null (e.g. the null string or -1 for positive integers).

这篇关于是否可以随机排序,并查询字段是否存在?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆