我已经实现了一个脚本字段,返回像这里的距离在elasticsearch结果中返回距离?
红宝石:
{
script_fields: {
distance: {
script: "doc['#{source_field}'].distanceInKm(#{lat}, #{lng})"
}
}
}
Run Code Online (Sandbox Code Playgroud)
但是返回的距离不正确.如果该点接近,则距离更正确,但随着距离越来越远,它变得越来越不正确.
似乎无法弄清楚我做错了什么.
你如何缩小图像直到一方用Carrierwave和rmagick达到它的目标维度?
例:
目标尺寸:600x400
正在上传的图片:700x450
我希望缩小此图像,直到高度达到400像素,保持原始高宽比.
这将导致具有以下尺寸的图像:622x400
嗨,我是mongoDB和Mongoid的新手,对于何时使用嵌入式文档以及嵌入的深度有点困惑.
这是一个虚构的例子:
Library collection has_many :books, which embeds_many :pages, which embeds_many :sections
由于我不能直接说一节,我必须通过books.pages.sections,对吧?
这将导致这条路线,libraries/:id/books/:id/pages/:id/sections/:id
这似乎有点疯狂,最佳做法是只嵌套一层深,对吧?一种方法是拥有路线pages/:id/sections/:id,然后将bookid粘贴在请求中?
查询说,部分会更难吗?例如,如果我需要查找部分标记为x的所有书籍?
但是,如果我没有一直嵌入我会有额外的查询?
有人可以解释一下吗?谢谢.
你将如何测试这门课?您会将其与 Resque 集成并检查作业是否已放入队列中,或者您会模拟它吗?如果您要模拟它,您将如何避免重复示例规范中所示的代码。
class BookingReminderEnqueuer
def initialize(user, booking, worker = BookingReminder)
@user, @booking, @worker = user, booking, worker
end
def enqueue
Resque.enqueue_at(
remind_user_at,
@worker,
booking_id: @booking.id,
user_id: @user.id
) if @booking.remind_user?
end
private
def remind_user_at
@booking.start_time - 6.hours
end
end
require 'spec_helper'
describe BookingReminderEnqueuer
describe "#enqueue" do
context "when the user should have a reminder" do
it "enqueues the reminder" do
booking.stub(:remind_user?) { true }
Resque.should_receive(:enqueue_at).with(
booking.start_time - 6.hours,
BookingReminder,
booking_id: booking.id,
user_id: user.id
).once
booking_reminder_enqueuer.enqueue
end
end
context "when …Run Code Online (Sandbox Code Playgroud) 是否可以添加一个布尔的自定义脚本字段,如果文档的id存在于作为参数发送的数组中,则返回true?
像这样的东西https://gist.github.com/2437370
用mvel做这个的正确方法是什么?
更新: 无法按照Imotov的答案指定工作.
制图:
分类:
:sort=>{:_script=>{:script=>"return friends_visits_ids.contains(_fields._id.value)", :type=>"string", :params=>{:friends_visits_ids=>["4f8d425366eaa71471000011"]}, :order=>"asc"}}}
place: {
properties: {
_id: { index: "not_analyzed", store: "yes" },
}
}
我没有得到任何错误,文件只是没有正确排序.
更新2
哦,我确实在文件上得到了回复:
"sort"=>["false"]