Question

In my app I have a number of models that i'd like to add multisearch to, I feel like I've done everything required but in the console when I run the following i get back an empty [].

PgSearch.multisearch("Red")

so here's what I've done

rails g pg_search:migration:multisearch
rake db:migrate

created an initializer which includes

PgSearch.multisearch_options = {
:using => [:tsearch, :trigram],
:ignoring => :accents
}

I've also created those extensions

In each of the models i wanted to search I added the following

include PgSearch
multisearchable :against => [:name]

I then created a results controller, here's whats in there

class ResultsController < ApplicationController

 def index
  @pg_search_documents = PgSearch.multisearch(params[:query])
 end
end

I get no errors when running the searches from the console, just no results even though I know there are items that fit what I'm searching for.

Does pg_search go through items created previous to adding pg_search? Does anyone have any clues as to what I'm doing wrong? What I may have missed.

Thanks

Edit: sorry I should also mention I'm using rails 3.2.8 and ruby 1.9.2, I've added pg_search to my gemfile and run rake db:migrate

Was it helpful?

Solution

Ah, obvious one, I had rebuild my records for pg-search to access them. Hope this helps someone in the future.

rake pg_search:multisearch:rebuild[BlogPost]
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top