mydogmoki
mydogmoki

Reputation: 1

Search always returns every record in the table

I created a simple full text search rails app using the sunspot_rails and sunspot_solr gems. The search always returns every record from the database regardless of the search term.

class FooController < ApplicationController
  def search
    @foos = Foo.search do
      fulltext params[:query]
    end.result

    respond_to do |format|
      format.html { render :action => "index" }
      format.xml { render :xml => @foos }
    end
  end
end
class Foo < ApplicationRecord
  searchable do
    text :name
  end

end
  resources :foos do
    collection do
      get :search
    end
  end

gem 'rails', '~> 5.1.0'
gem 'sunspot_rails','~> 2.5.0'
gem 'sunspot_solr','~> 2.5.0'

I run bundle exec rake sunspot:reindex before going to the index page, type any search term and the controller returns every record in the foos table regardless of the search term I give it.

Upvotes: 0

Views: 28

Answers (1)

Joel Cahalan
Joel Cahalan

Reputation: 409

I looked at the docs and couldn't find a .result method but there is a .results which the docs say return an array with the first 30 results by default. Maybe this is your issue?

Upvotes: 0

Related Questions