Search code examples
ruby-on-railssearchsolrsunspot

sunspot solr: search for "Everything" / wildcard


How would one search in Sunspot solr with a wildcard? Use * does not work, I want to return all the results for education.

Education is a collection that can exists of "All", "High", "Low", so now my idea is to remove it from the search block if its "All"

with(:orientation, params[:orientation])  
if params[:orientation].present? unless params[:orientation] == "all"

Must be a better way?

Search block:

search = Sunspot.search Session do

      if params[:education].present?
        if params[:education] == "all"
          # Use a wildcard here
          #with(:education, *)
        end
      end
end

Solution

  • The best way is actually to remove the query as you say. It's cleaner and is quicker because the engine has one less condition to run. So:

    with(:orientation, params[:orientation])  
    if params[:orientation].present? unless params[:orientation] == "all"
    

    is indeed the best solution.