我需要为我的应用程序做面。目前,我希望在搜索后的结果页面上显示方面。我是新来的铁路公司,很抱歉我的英语不好,我是法国人。
我有两个模型: Camping.rb和Caracteristiquetest.rb。我做了联想has_many / belongs_to。在讽刺中,我有一个列camping_id和其他字符串列"piscine“和"barbecue”。
因此,经过大量测试后,我找到了一个在caracteristiquetest.barbecue上找到值为"non“的帖子的解决方案(参见后)。现在我试着把这个植入应用程序。
我有个错误:
C:/Sites/campsite/app/models/BUPing.Rb:66:语法错误,意外':',期望=> {caracteristiquetest.barbecue:“non”}^C:/Sites/campsite/app/model/ keyword_end .of:66:语法错误,意外'}',期待keyword_end {caracteristiquetest.barbecue:“non”}]^C:/keyword_end{caracteristiquetest.barbecue/app/models/keyword_end:85:语法错误,意外结束-输入,期待keyword_end
怎么才能修好它呢?顺便说一句,修完之后我怎么能把这个植入我的妻子身上?我想在搜索后植入这个功能,让用户过滤“烧烤”“是”/“否”。
谢谢你的帮助。
_search与head_plugin elasticsearch一起运行时,我得到了很好的结果
{
"query": {
"bool": {
"must": [
{"term":
{"caracteristiquetest.barbecue": "non"}}]
}
}
}campings_controller.rb
def homesearch
@campings = Camping.custom_search((params[:q].present? ? params[:q] : '*'))
end
#Page de résultats
def result
if params[:q].blank?
redirect_to action: :index and return
else
@campings = Camping.custom_search((params[:q].present? ? params[:q] : '*')).page(params[:page]).per(14).results
end
endcamping.rb
mapping do
indexes :name, boost: 8
indexes :adresse
indexes :commune, boost: 10
indexes :description
indexes :nomdep, boost: 10
indexes :nomregion, boost: 10
indexes :ville_id
indexes :region_id
indexes :departement_id
indexes :latitude
indexes :longitude
indexes :etoile
indexes :user_id
indexes :caracteristiquetest_id
#On implante les données du modèle supplémentaire
indexes :caracteristiquetests, type: 'nested' do
indexes :id, type: 'integer'
indexes :piscine, type: 'string'
indexes :barbecue, type: 'string'
indexes :camping_id, type: 'integer'
end
end
def as_indexed_json(options = {})
self.as_json(only: [:name, :adresse, :code_postale, :commune, :description, :nomdep, :nomregion, :latitude, :longitude, :etoile, :caracteristiquetest_id],
include: {caracteristiquetest: {only: [:id, :piscine, :barbecue, :camping_id]}})
end
class << self
def custom_search(query)
__elasticsearch__.search(query: multi_match_query(query), aggs: aggregations)
end
def multi_match_query(query)
{
multi_match: {
query: query,
type: "best_fields",
fields: ["name^6", "nomdep^10", "commune^8", "nomregion^7"],
operator: "and"
}
}
end
def aggregations
{
query: {
bool: {
must: [
{term:
{caracteristiquetest.barbecue : "non"}}]
}
}
}
end
endhomesearch.html.erb
<div class="container">
<div class="row">
<div class="search">
<%= form_tag(result_path, method: :get) %>
<%= text_field_tag :q, params[:q], class:"search-query form-control" %>
<%= submit_tag "GO", class:"btn btn-danger", name: nil %>
</div>
</div>
</div>发布于 2016-08-29 16:04:30
您正在尝试与Elasticsearch返回的响应的results接口进行交互。尝试直接与response对象交互。
# don't call `.results` here because you want the full response object
@campings = Camping.__elasticsearch__.search(...)根据文件
返回的response对象是从Elasticsearch返回的JSON的丰富包装器,提供了对响应元数据和实际结果("hits")的访问。
来源:results
您应该能够通过检查生成的JSON并阅读Elasticsearch文档本身来了解如何获取您需要的方面和任何其他数据。
https://www.elastic.co/guide/en/elasticsearch/reference/current/index.html
https://stackoverflow.com/questions/39209743
复制相似问题