如何使用elasticsearch进行排序?(How to sort with elasticsearch?)
我正在尝试制作排序
desc
和asc
。 我正在使用rails,tire gem和elasticsearch。 我试图弄清楚我可以在URL中发送什么类型的参数所以我在搜索块中定义它正在对结果desc顺序进行排序。
sort { by :price, "desc"}
当用户在: new-york中搜索公寓时,结果是排序顺序。
搜索查询/ URL如下所示:
http://localhost:3000/apartmens?utf8&query=newyork
为什么我不能在网址中添加sort-params,如下所示:
http://localhost:3000/apartmens?utf8&query=newyork&sort=asc
I am trying to make methods for sorting
desc
andasc
. I am using rails, tire gem and elasticsearch. I am trying to figure out what sort params I can send in the URLSo I have defined in the search-block that it is sorting the result desc order.
sort { by :price, "desc"}
When a user search for apartments in: new-york the result is sort desc order.
The search query/URL looks like this:
http://localhost:3000/apartmens?utf8&query=newyork
Why cant I add a sort-params in the url, like this:
http://localhost:3000/apartmens?utf8&query=newyork&sort=asc
原文:https://stackoverflow.com/questions/14756149
最满意答案
thread.start_new_thread
返回线程标识符,而不是thread.start_new_thread
本身。 所以你实际上附加了整数的胎面标识符。您可以创建并启动一个Thread对象(为此您需要从线程中导入Thread),然后您将获得对它的引用
例如:
t = Thread(target=your_target, args=your_args) t.start() threads.append(t)
thread.start_new_thread
returns the thread identifier, not the tread itself. So you are actually appending the tread identifiers which are integers.You could create and start a Thread object (for that you need to import Thread from threading) then you would have a reference to it
Ex:
t = Thread(target=your_target, args=your_args) t.start() threads.append(t)
相关问答
更多-
使用push()函数附加到数组: // initialize array var arr = [ "Hi", "Hello", "Bonjour" ]; // append new value to the array arr.push("Hola"); console.log(arr); 会打印 ["Hi", "Hello", "Bonjour", "Hola"] 您可以使用push()函数在单个调用中将多个值附加到数组: // initialize ar ...
-
您可以使用json.loads解析JSON,执行操作,然后通过json.dumps转换回JSON。 请注意,我必须编辑您的JSON才能使其有效。 (“Gateway”缺少封闭的双引号。) import json values = [20.8, 21.2, 22.4] timeStamps = ["2013/25/11 12:23:20", "2013/25/11 12:25:20", "2013/25/11 12:28:20"] myJSON = '{ "Gateway": {"serial":"1 ...
-
无法将线程附加到数组(Can't append thread to array)[2023-09-15]
thread.start_new_thread返回线程标识符,而不是thread.start_new_thread本身。 所以你实际上附加了整数的胎面标识符。 您可以创建并启动一个Thread对象(为此您需要从线程中导入Thread),然后您将获得对它的引用 例如: t = Thread(target=your_target, args=your_args) t.start() threads.append(t) thread.start_new_thread returns the thread ide ... -
一步一步。 理想情况下,您应该确定响应不同的原因。 由于您说这些差异通常与您的请求中的不同内容相对应,因此强烈建议您可能忽略(或可能误解)远程API中的某些内容。 我建议重新审核API以识别“某些东西”,以便找出正确的方法。 否则,当您继续调整代码以处理每个“新”情况时,代码将很快变得难以管理且效率低下。 如果出于某种原因,API确实在没有正当理由的情况下返回不同的结果,那么您可以做的最好的事情是根据您的期望进行编码,并在收到其他内容时优雅地失败。 首先列出预期的可能性: 响应是包含某些键OR的单个结构 R ...
-
您可能需要将数组定义为包含可变数组,如下所示。 var returnObject = [NSMutableArray]() 你也可以使用一个Swift'sub'数组,并将它定义为更像这样。 var returnObject = Array
>() 不要忘记更新方法的回报。 func getJSON() -> Array > You may need to define the array as containing a mutable array a ... -
无法弄清楚如何附加到数组(在结构中)(Swift)(Can't figure out how to append to an array (within a struct) (Swift))[2022-08-13]
在为结构或类定义接口时,可以执行的操作类型存在限制。 您可以对值进行一些基本的初始化,但不允许调用append()等方法。 这是对代码的快速调整,我将附加内容移动到init()方法中: struct Toolkit { var tools = [ [ "name": "Know Yourself to Lead Yourself", "shape": "icon_knowyourself.pdf", "image": "know_yourself_to ... -
将append()附加到另一个线程正在读取的切片是否安全?(Is is safe to append() to a slice from which another thread is reading?)[2020-12-08]
问题中的代码是不安全的,因为它在一个goroutine中读取变量并在没有同步的情况下修改另一个goroutine中的变量。 这是使代码安全的一种方法: type Obj struct { mu sync.Mutex // add mutex ... // other fields as before } func (o *Obj) Reader() { o.mu.Lock() data := o.data o.mu.Unlock() for i, value : ... -
将哈希附加到数组(Append Hash to Array)[2023-08-07]
问题并不完全清楚,但如果我理解正确,可以提供一个可以接受或不接受前一个Block的类。 你觉得那样的事怎么样? #!/usr/bin/env ruby class Block < Hash def initialize(h, b=nil) [:x, :y, :z].each do |s| # We start by trying to assign the coordinate that is in the # input hash if h[s] ... -
这是关于值类型与引用类型的常见混淆,来自Java或C ++背景。 当您将用户的内容分配给本地变量user ,然后在样本底部变异该变量时,您只需要修改本地副本。 将用户更改为一个class ,所有都可以。 从风格上讲,如果您在代码中使用强制解包,则还应该在底部使用强制解包,因为您不希望它以静默方式失败。 或者,保持结构,但在完全变异之前不要将user放入users 。 This is the usual confusion about value types versus reference types, c ...
-
附加到Clickhouse中的数组(Append to array in Clickhouse)[2024-02-21]
您无法修改表中的数据,因为ClickHouse中的所有数据都是不可变的。 但是 :您可以在选择期间即时添加,或者您可以制作一个VIEW,它将为您完成。 如果您确实需要以更改状态存储该列 - 您需要创建表副本或物化视图。 这些函数可以是有用的arrayConcat,arrayPushBack,arrayPushFront(文档即将发布)。 所以 SELECT CASE WHEN condition > 10 THEN arrayPushBack(array_field, 'extra_elemen ...