I have a Person model that I wish to perform searches against.
class Person < ActiveRecord::Base
searchable do
text :first_name, :last_name, :boost => 2
text :email, :phone
end
end
I've pulled the search function out of the people_controller because in the long run Im hoping to increase the scope to search all models. Here is the search controller
class SearchController < ApplicationController
def index
@people = Person.search do
fulltext params[:search]
end
@results = @people.results
end
end
Im using UJS to render the search results in a search pane on the page. at the moment search/index.js.erb appends the debug output of the above @results variable.
$('#search-results').empty();
$('#search-results').append('<%= j debug @results %>');
Every query I attempt returns the following result.
--- !ruby/array:Sunspot::Search::PaginatedCollection
internal: []
ivars:
:@current_page: 1
:@per_page: 30
:@total_count: 0
and in the rails console the following is shown.
Parameters: {"utf8"=>"✓", "search"=>"Sabrina", "commit"=>"Go"}
SOLR Request (4.7ms) [ path=select parameters={fq: ["type:Person"], q: "Sabrina", fl: "* score", qf: "first_name_text last_name_text email_text phone_text", defType: "edismax", start: 0, rows: 30} ]
Its important to note that this query is copy/pasted from one of the people in the database. Initially I was worried that the error tolerance wasn't allowing for even minor misspellings.
This is starting to get pretty frustrating, so far I have deleted and reinstalled the latest JDK, and restarted my machine. At this point I havn't seen any errors or failed dependancies, etc. With one possible exception: When I run rake sunspot:solr:reindex
I get only the following in the terminal
Skipping progress bar: for progress reporting, add gem 'progress_bar' to your Gemfile
My question is this: What am I doing wrong?
Try this
class SearchController < ApplicationController
def index
@people = Sunspot.search(Person) do
fulltext params[:search]
end
@results = @people.results
end
end