gpt4 book ai didi

sunspot - 设置太阳黑子地理定位场景

转载 作者:行者123 更新时间:2023-12-04 18:49:41 36 4
gpt4 key购买 nike

我正在使用 Sunspot用于搜索和使用 Geocoder对于地址,然后用于计算距离,Geokit-rails3 .

class Product < ActiveRecord::Base
belongs_to :store
searchable do
text :name
end
end

class Store < ActiveRecord::Base
acts_as_mappable
geocoded_by :address, :latitude => :lat, :longitude => :lng
attr_accessible :lat, :lng, :address
has_many :products
end



在输入要搜索的产品时,我还希望能够在另一个字段内输入地址以搜索半径 30 英里的给定区域内的产品。

这是我的 Controller ,它允许我搜索产品:
class SearchController < ApplicationController

def index
@search = Product.search do |q|
q.fulltext params[:search]
end
@products = @search.results
end
end

所以我相信表格在我完成后看起来会像这样:
<%= form_tag search_path, :method => 'get' do %>
<%= text_field_tag :search, params[:search]" %>
<%= submit_tag "Search", :name => nil %>
<p> Search Near: </p>
<%= label_tag :location, "Search nearby an Address" %>
<%= text_field_tag :location, params[:location] %>
<% end %>

我在想 :location将作为 Stores :address 的虚拟属性为了正确映射该字段,但这都是推测。

我如何设置这一切以实现特定场景?

最佳答案

一定要结账this RailsCast .我认为它完全回答了你的问题。

关于sunspot - 设置太阳黑子地理定位场景,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8206726/

36 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com