Giter VIP home page Giter VIP logo

refinerycms-search's Introduction

Refinery CMS Search Build Status

Simple search engine for Refinery CMS. By default it supports search in Refinery::Page, and Refinery::Blog::Post (if installed), but it can be easily configured for other Rails models too.

This version of refinerycms-search supports Refinery 3.x and Rails 4.1.x. For Refinery 2.1.x and Rails 3.x, use the 2-1-stable branch.

Powered by: acts_as_indexed and refinerycms-acts-as-indexed - Check his readme and documentation for more info on how it works.

In summary you can

  • Search in Refinery::Page and Refinery::Blog::Post models
  • Add others models in your configuration
  • Scope search query with a special method
  • Use a custom search page URL
  • Paginate the search result

What it can't do :

  • It can't search all languages in the same query: it only display the results of the current locale.

Requirements

Refinery CMS version 3.0.0 or above.

Installation

Open up your Gemfile and at the bottom, add this line:

gem 'refinerycms-search', github: 'refinery/refinerycms-search', branch: 'master'

Now, run bundle install

Next, to install the search plugin run:

rails generate refinery:search

Run database migrations:

rake db:migrate

Finally seed your database and you're done.

rake db:seed

Index records

You will have to RE-SAVE all records that have not been indexed before.

You can do it easily with a command like this in rails console :

Refinery::Page.all(&:save)

Search form

A sample search form can be found in views/refinery/shared/_search.html.erb. You can either use this partial directly, or copy the appropriate parts.

Searchable models

The default installation will search in Refinery::Page and Refinery::Blog::Post (if installed). If you wish to find results in other plugins you have created or installed, you can specify these in config/initializers/refinery/search.rb like so:

config.enable_for = ['Refinery::Page']

Simply add any additional models you wish to search to this array. For example, if you have the portfolio plugin installed:

config.enable_for = ['Refinery::Page', 'Refinery::PortfolioEntry']

The above line will add indexing to PortfolioEntry in the portfolio plugin, which does not come indexed.

Any model you wish to search will need to be indexed using acts as indexed. To add indexing, simple add:

acts_as_indexed :fields => [:title, :body]

If your model doesn't use a :title attribute, remember to add an alias_attribute:

alias_attribute :title, :name #for example

You can use any public method, as well. So if you have :first_name and :last_name but a method like name to join them, it can be indexed.

acts_as_indexed :fields => [:name, :biography]

#...

def name
  [first_name, last_name].reject(&:blank?).join(' ')
end

You will need to replace the indexed fields with those appropriate for your model.

If you wish to override the url used in the search results just add a url method to your model and the result of this method will be used instead.

Displaying a friendlier name for your model

Just define the method friendly_search_name to override what is displayed for each search result for your model as per the implementing pull request.

def friendly_search_name
  "Document"
end

Use refinery_search_scope on searchable models

If you want to add a custom scope on a searchable model, you can use the method refinery_search_scope in your model.

# app/decorators/models/refinery/page_decorator.rb
Refinery::Page.class_eval do
  def self.refinery_search_scope
    live
  end
end

refinerycms-search's People

Contributors

parndt avatar ugisozols avatar joemsak avatar anitagraham avatar bricesanchez avatar awagener avatar chrisftw avatar markprovan avatar djones avatar matho avatar adamico avatar snowsunny avatar duarme avatar robyurkowski avatar nickurban avatar mirosr avatar mattherick avatar mhaylock avatar mamedov avatar kgautreaux avatar simi avatar dmoose avatar snake66 avatar

Watchers

 avatar James Cloos avatar Alessandro Rodi avatar Marta Petrella avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.