Indexed Search Engine plugin

Plugin details

IndexedSearchEngine is a simple, pluggable engine for rails applications which can be used to enable full text indexed searches within an application.

Repositoryhttp://langwell-ball.com/svn/indexed-search/trunk/indexed_search_engine/ Author Lance Ball Tags Search LicenseUnknown

Documentation

Install the plugin:
ruby script/plugin install http://langwell-ball.com/svn/indexed-search/trunk/indexed_search_engine/

The IndexedSearchEngine provides a default stylesheet, so you'll want to include it in your application's layout. Add the following line:

      <%= engine_stylesheet "indexed_search_engine" %>


To use the default search field and results templates include this in your layout.

  <%= render :partial => 'search/search_field' %>


If you want to use the partials provided with the engine, you will also need to include the default javascript files for all rails applications:

  <%= javascript_include_tag :defaults %>


Add the following to your controllers or app/controllers/application.rb

  include IndexedSearchEngine
  helper :search


To index data, add calls to IndexableRecord.index_records in your controllers. For example:

  def create
    @item = Item.new(params[:item])
    if @item.save
      flash[:notice] = 'Item was successfully created.'
      redirect_to :action => 'edit', :id => @item
    
      # Index the item for searching
      url = url_for :action => 'show', :id => @item, :only_path => true
      index_data = IndexableRecord::IndexData.new(:content => @item.description, :uri => url, :title => @item.name)
      IndexableRecord.index_records(index_data)
    else
      render :action => 'new'
    end
  end


To update a record, call IndexableRecord.update_index

  def update
    @item = Item.find(params[:id])
    if @item.update_attributes(params[:item])
      redirect_to :action => 'show', :id => @item

      # Update the indexed search data
      url = url_for :action => 'show', :id => @item, :only_path => true
      index_data = IndexableRecord::IndexData.new(:content => @item.description, :uri => url, :title => @item.name)
      IndexableRecord.update_index(index_data)
      flash[:notice] = 'Item was successfully updated.'
    else
      render :action => 'edit'
    end
  end


To delete indexes search records, call IndexableRecord.clear_index

  def destroy
    @item = Item.find(params[:id])
    # Remove the item from search index
    url = url_for :action => 'show', :id => @item, :only_path => true
    IndexableRecord.clear_index(url)
    @item.destroy
    redirect_to :action => 'list'
  end


And you are done!

Further Documentation

There is currently no advanced documentation for this plugin.

New documentation

Edit plugin | (0 older versions) | Last edited by: hardway, 7 months ago