我编写了以下类来从 solr 获取与给定查询相对应的结果
class Recommendation
class GetResults
attr_accessor :query, :filter, :sort, :facet, :highlight, :filter_fields, :sort_order, :highlight_fields, :facet_query, :facet_fields, :sort_field
def initialize(query, filter=false, sort=false, facet=false, highlight=false, filter_fields=nil, sort_order=nil, sort_field=nil, highlight_fields=nil, facet_query=nil, facet_fields=nil)
@query = query
@filter = filter||false
@sort = sort||false
@facet = facet||false
@highlight = highlight||false
@filter_fields = filter_fields||nil
@sort_order = sort_order||nil
@sort_field = sort_field||nil
@highlight_fields = highlight_fields||nil
@facet_query = facet_query||nil
@facet_fields = facet_fields||nil
end
def obtain_results
h=Net::HTTP.new('localhost',8983)
@query_path = '/solr/voylla/select/?indent=on&q=%s&wt=ruby' % query
if @filter==true
#puts "hello filter"
@query_path = @query_path.to_s + "&fl=%s" % @filter_fields
puts @query_path
end
if @sort==true
#puts "hello sort"
@query_path = @query_path.to_s + "&sort=%s "+"%s" % @sort_field,@sort_order
puts @query_path
end
#hsrep, data = h.get(@query_path)
#rsp = eval(data)
#puts rsp
end
end
end
results=Recommendation::GetResults.new(query='ring', filter=true, sort=true, filter_fields='allText,Price', sort_order='asc', sort_field='Price')
results.obtain_results
与此相关的问题@query_path
没有按需要更新。输出是:
hello filter
/solr/voylla/select/?indent=on&q=ring&wt=ruby&fl=Price
hello sort
/solr/voylla/select/?indent=on&q=ring&wt=ruby&fl=Price&sort=%s
所需的输出是:
hello filter
/solr/voylla/select/?indent=on&q=ring&wt=ruby&fl=allText,Price
hello sort
/solr/voylla/select/?indent=on&q=ring&wt=ruby&fl=allText,Price&sort=Price asc