Sha256: 2af5f7dc7de72c4c67056803fad052c2a630fcb32848f999cdd6d4d2cda7d708

Contents?: true

Size: 1.19 KB

Versions: 11

Compression:

Stored size: 1.19 KB

Contents

module Documentation
  module Searchers
    class Simple < Documentation::Searchers::Abstract
      
      def search(query, options = {})
        # Default options
        options[:page]      ||= 1
        options[:per_page]  ||= 15
        
        # Query string 
        query_string = "content LIKE ? OR title LIKE ?", "%#{query}%", "%#{query}"
        
        # Get the total number of pages
        total_results = pages = Documentation::Page.where(query_string).count
        
        # Get the actual pages
        pages = Documentation::Page.where(query_string)
        pages = pages.offset((options[:page].to_i - 1) * options[:per_page].to_i)
        pages = pages.limit(options[:per_page].to_i)
        
        # Create a result object
        result                = Documentation::SearchResult.new
        result.page           = options[:page].to_i
        result.per_page       = options[:per_page].to_i
        result.total_results  = total_results
        result.query          = query
        result.time           = 0
        result.results        = pages
        
        # Return the result
        result
      end
      
      def index(page)
        true
      end
      
    end
  end
end

Version data entries

11 entries across 11 versions & 2 rubygems

Version Path
documentation-1.0.9 lib/documentation/searchers/simple.rb
documentation-1.0.8 lib/documentation/searchers/simple.rb
documentation-1.0.7 lib/documentation/searchers/simple.rb
documentation-1.0.6 lib/documentation/searchers/simple.rb
local_documentation-1.0.0 lib/documentation/searchers/simple.rb
documentation-1.0.5 lib/documentation/searchers/simple.rb
documentation-1.0.4 lib/documentation/searchers/simple.rb
documentation-1.0.3 lib/documentation/searchers/simple.rb
documentation-1.0.2 lib/documentation/searchers/simple.rb
documentation-1.0.1 lib/documentation/searchers/simple.rb
documentation-1.0.0 lib/documentation/searchers/simple.rb