Skip to content

Instantly share code, notes, and snippets.

@francois-blanchard
Last active January 20, 2016 15:53
Show Gist options
  • Save francois-blanchard/6d0ee8b7d9a07290c82e to your computer and use it in GitHub Desktop.
Save francois-blanchard/6d0ee8b7d9a07290c82e to your computer and use it in GitHub Desktop.
Full search specific fields with sunspot (SOLR)

Full search specific fields with sunspot (SOLR)

Doc

gem sunspot - all doc

Example

Class Post
  # ...
  searchable do
    text :title
    text :body
    text :tags
  end
  
  def self.search(params)
    Post.solr_search do
      ...
    end
  end
  # ...
end

Global search

Search on all text fields

# ...

Post.solr_search do
  keywords params[:search]
end

# ...

Search on specific fields

Search on specific text fields with specific text params

# ...

Post.solr_search do
  fulltext params[:title], fields: :title
  fulltext params[:search], fields: [:body, :tags]
end

# ...
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment