Hi Alex

In this case, you'll only want to add things if they're being used:

  query = [:query, :name, :direction, :country].select { |key|
    params[key].present?
  }.collect { |key| params[key] }.join(' | ')
  filters = {}
  if params[:cost_from].present? && parama[:cost_to].present?
    filters[:cost] = params[:cost_from].to_f..params[:cost_to].to_f
  end

  @tours = Tour.search query, :with => filters

You'll note that I've removed the match mode - TS v3 uses SphinxQL (as you've 
seen in your logs), and SphinxQL only supports the extended match mode. Thus, 
I'm joining each query part with a pipe character (Sphinx's OR boolean syntax). 
Granted, this doesn't split multiple words in any of those query params with 
pipes, so perhaps you'll need to take care of that too.

-- 
Pat


On 28/08/2013, at 7:15 PM, alex wrote:

> Just one more question
> 
> ThinkingSphinx::Index.define :tour, :with => :active_record do
>    #fields
>    indexes summary
>    indexes country, direction, sortable: true
>    indexes :name, sortable: true
>    # attributes
>    has cost
> end
> ------------------------------------------------------------------------------------
> @tours = Tour.search("#{params[:query]} #{params[:name]}
>                                  #{params[:direction]} #{params[:country]}",
>                                  :with => {:cost => 
> params[:cost_from]..params[:cost_to]},
>                                  :match_mode => :any)
> 
> Now cost field became obligatory, if I left it blank when searching, such 
> error occurs:  sphinxql: syntax error, unexpected AND, expecting CONST_INT or 
> CONST_FLOAT or '-' near 'AND  AND sphinx_deleted = 0 LIMIT 0, 20; SHOW META'
> 
> 
> -- 
> You received this message because you are subscribed to the Google Groups 
> "Thinking Sphinx" group.
> To unsubscribe from this group and stop receiving emails from it, send an 
> email to [email protected].
> To post to this group, send email to [email protected].
> Visit this group at http://groups.google.com/group/thinking-sphinx.
> For more options, visit https://groups.google.com/groups/opt_out.


-- 
You received this message because you are subscribed to the Google Groups 
"Thinking Sphinx" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
Visit this group at http://groups.google.com/group/thinking-sphinx.
For more options, visit https://groups.google.com/groups/opt_out.

Reply via email to