Permalink
Browse files

removing unused whitespace

  • Loading branch information...
ryanb committed Apr 14, 2011
1 parent 6935aac commit 4959550e843fcebbb84ed51ed8a281a6b238da22
Showing with 374 additions and 374 deletions.
  1. +2 −2 CHANGELOG.rdoc
  2. +4 −4 LICENSE
  3. +9 −9 README.rdoc
  4. +7 −7 lib/xapit.rb
  5. +6 −6 lib/xapit/adapters/abstract_adapter.rb
  6. +3 −3 lib/xapit/adapters/active_record_adapter.rb
  7. +1 −1 lib/xapit/adapters/data_mapper_adapter.rb
  8. +27 −27 lib/xapit/collection.rb
  9. +13 −13 lib/xapit/config.rb
  10. +1 −1 lib/xapit/document.rb
  11. +8 −8 lib/xapit/facet.rb
  12. +8 −8 lib/xapit/facet_blueprint.rb
  13. +6 −6 lib/xapit/facet_option.rb
  14. +21 −21 lib/xapit/index_blueprint.rb
  15. +17 −17 lib/xapit/indexers/abstract_indexer.rb
  16. +2 −2 lib/xapit/indexers/classic_indexer.rb
  17. +3 −3 lib/xapit/indexers/simple_indexer.rb
  18. +11 −11 lib/xapit/local_database.rb
  19. +23 −23 lib/xapit/membership.rb
  20. +12 −12 lib/xapit/query.rb
  21. +24 −24 lib/xapit/query_parsers/abstract_query_parser.rb
  22. +3 −3 lib/xapit/query_parsers/classic_query_parser.rb
  23. +6 −6 lib/xapit/query_parsers/simple_query_parser.rb
  24. +1 −1 rails_generators/xapit/USAGE
  25. +1 −1 rails_generators/xapit/xapit_generator.rb
  26. +3 −3 spec/xapit/adapters/active_record_adapter_spec.rb
  27. +33 −33 spec/xapit/collection_spec.rb
  28. +10 −10 spec/xapit/config_spec.rb
  29. +4 −4 spec/xapit/facet_blueprint_spec.rb
  30. +8 −8 spec/xapit/facet_option_spec.rb
  31. +11 −11 spec/xapit/facet_spec.rb
  32. +14 −14 spec/xapit/index_blueprint_spec.rb
  33. +13 −13 spec/xapit/indexers/abstract_indexer_spec.rb
  34. +3 −3 spec/xapit/indexers/classic_indexer_spec.rb
  35. +7 −7 spec/xapit/indexers/simple_indexer_spec.rb
  36. +8 −8 spec/xapit/membership_spec.rb
  37. +8 −8 spec/xapit/query_parsers/abstract_query_parser_spec.rb
  38. +3 −3 spec/xapit/query_parsers/classic_query_parser_spec.rb
  39. +14 −14 spec/xapit/query_parsers/simple_query_parser_spec.rb
  40. +7 −7 spec/xapit/query_spec.rb
  41. +9 −9 spec/xapit_member.rb
View
@@ -5,14 +5,14 @@
* fixing nested search calls
* chain a separate search with "or_search" to find records matching either one
-
+
search("foo").or_search(:conditions => { :priority => 3 })
*0.2.6* (July 6th, 2009)
* search for field conditions in query string, only supported by ClassicQueryParser
-
+
search("age:17")
* check if xapian database exists before removing
View
@@ -1,16 +1,16 @@
-Copyright (c) 2008 Ryan Bates
-
+Copyright (c) 2011 Ryan Bates
+
Permission is hereby granted, free of charge, to any person obtaining
a copy of this software and associated documentation files (the
"Software"), to deal in the Software without restriction, including
without limitation the rights to use, copy, modify, merge, publish,
distribute, sublicense, and/or sell copies of the Software, and to
permit persons to whom the Software is furnished to do so, subject to
the following conditions:
-
+
The above copyright notice and this permission notice shall be
included in all copies or substantial portions of the Software.
-
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
View
@@ -17,7 +17,7 @@ To install as a Rails plugin, run this command.
Or to install as a gem in Rails first add this to config/environment.rb.
config.gem 'xapit'
-
+
And then install the gem and run the generator.
sudo rake gems:install
@@ -84,25 +84,25 @@ There are two projects in development to help improve this reindexing.
== Search
You can then perform a search on the model.
-
+
# perform a simple full text search
@articles = Article.search("phone")
-
+
# add pagination if you're using will_paginate
@articles = Article.search("phone", :per_page => 10, :page => params[:page])
-
+
# search based on indexed fields
@articles = Article.search("phone", :conditions => { :category_id => params[:category_id] })
-
+
# search for multiple negative conditions (doesn't match 3, 5, or 8)
@articles = Article.search(:not_conditions => { :category_id => [3, 5, 8] })
-
+
# search for range of conditions by number
@articles = Article.search(:conditions => { :released_at => 2.years.ago..Time.now })
-
+
# manually sort based on any number of indexed fields, sort defaults to most relevant
@articles = Article.search("phone", :order => [:category_id, :id], :descending => true)
-
+
# basic boolean matching is supported
@articles = Article.search("phone OR fax NOT email")
@@ -193,5 +193,5 @@ This project can be found on github at the following URL.
http://github.com/ryanb/xapit
-If you would like to contribute to this project, please fork the
+If you would like to contribute to this project, please fork the
repository and send me a pull request.
View
@@ -9,20 +9,20 @@ module Xapit
def self.index_all(*args, &block)
IndexBlueprint.index_all(*args, &block)
end
-
+
# Used to perform a search on all indexed models. The returned collection can
# contain instances of different classes which were indexed.
- #
+ #
# # perform a simple full text search
# @records = Xapit.search("phone")
- #
+ #
# See Xapit::Membership for details on search options.
def self.search(*args)
Collection.new(nil, *args)
end
-
+
# Setup configuration options. The following options are supported.
- #
+ #
# <tt>:database_path</tt>: Where the database is stored.
# <tt>:stemming</tt>: The language to use for stemming, defaults to "english".
# <tt>:spelling</tt>: True or false to enable/disable spelling, defaults to true.
@@ -33,12 +33,12 @@ def self.search(*args)
def self.setup(*args)
Config.setup(*args)
end
-
+
# Removes the configured database file and clears the stored one in memory.
def self.remove_database
Config.remove_database
end
-
+
def self.serialize_value(value)
if value.kind_of?(Date)
Xapian.sortable_serialise(value.to_time.to_i)
@@ -8,35 +8,35 @@ def self.inherited(subclass)
@subclasses ||= []
@subclasses << subclass
end
-
+
# Returns all adapter classes.
def self.subclasses
@subclasses
end
-
+
# Sets the @target instance, this is the class the adapter needs to forward
# its messages to.
def initialize(target)
@target = target
end
-
+
# Used to determine if the given adapter should be used for the passed in class.
# Usually one will see if it inherits from another class (ActiveRecord::Base)
def self.for_class?(member_class)
raise "To be implemented in subclass"
end
-
+
# Fetch a single record by the given id.
# The args are the same as those passed from the XapitMember#xapit call.
def find_single(id, *args)
raise "To be implemented in subclass"
end
-
+
# Fetch multiple records from the passed in array of ids.
def find_multiple(ids)
raise "To be implemented in subclass"
end
-
+
# Iiterate through all records using the given parameters.
# It should yield to the block and pass in each record individually.
# The args are the same as those passed from the XapitMember#xapit call.
@@ -4,15 +4,15 @@ class ActiveRecordAdapter < AbstractAdapter
def self.for_class?(member_class)
member_class.ancestors.map(&:to_s).include? "ActiveRecord::Base"
end
-
+
def find_single(id, *args)
@target.find_by_id(id, *args)
end
-
+
def find_multiple(ids)
@target.find(ids)
end
-
+
def find_each(*args, &block)
@target.find_each(*args, &block)
end
@@ -4,7 +4,7 @@ class DataMapperAdapter < AbstractAdapter
def self.for_class?(member_class)
member_class.ancestors.map(&:to_s).include? "DataMapper::Resource"
end
-
+
# TODO override the rest of the methods here...
end
end
View
@@ -1,7 +1,7 @@
module Xapit
# This is the object which is returned when performing a search. It behaves like an array, so you do not need
# to worry about fetching the results separately. Just loop through this collection.
- #
+ #
# The results are lazy loading, meaning it does not perform the query on the database until it has to.
# This allows you to string queries onto one another.
#
@@ -14,7 +14,7 @@ class Collection
delegate m, :to => :results unless m =~ /^__/ || NON_DELEGATE_METHODS.include?(m.to_s)
end
delegate :query, :base_query, :base_query=, :extra_queries, :extra_queries=, :to => :@query_parser
-
+
def self.search_similar(member, *args)
collection = new(member.class, *args)
indexer = SimpleIndexer.new(member.class.xapit_index_blueprint)
@@ -23,56 +23,56 @@ def self.search_similar(member, *args)
collection.base_query = query
collection
end
-
+
def initialize(*args)
@query_parser = Config.query_parser.new(*args)
end
-
- # Returns an array of results. You should not need to call this directly because most methods are
+
+ # Returns an array of results. You should not need to call this directly because most methods are
# automatically delegated to this array.
def results
@results ||= fetch_results
end
-
+
# The number of total records found despite any pagination settings.
def size
@query_parser.query.count
end
alias_method :total_entries, :size # alias to total_entries to support will_paginate
-
+
# Returns true if no results are found.
def empty?
@results ? @results.empty? : size.zero?
end
-
+
# The first record in the result set.
def first
fetch_results(:offset => 0, :limit => 1).first
end
-
+
# The last record in the result set.
def last
fetch_results(:offset => size-1, :limit => 1).last
end
-
+
# Perform another search on this one, inheriting all options already passed.
# See Xapit::Membership for search options.
#
# Article.search("kite").search("sky") # only performs one query
- #
+ #
def search(*args)
options = args.extract_options!
collection = Collection.new(@query_parser.member_class, args[0].to_s, @query_parser.options.merge(options))
collection.base_query = @query_parser.query
collection
end
-
+
# Chain another search returning all records matched by either this search or the previous search
# Inherits all options passed in earlier search (such as :page and :order)
# See Xapit::Membership for search options.
#
# Article.search("kite").or_search(:conditions => { :priority => 1 })
- #
+ #
def or_search(*args)
options = args.extract_options!
collection = Collection.new(@query_parser.member_class, args[0].to_s, @query_parser.options.merge(options))
@@ -81,44 +81,44 @@ def or_search(*args)
collection.extra_queries << @query_parser.primary_query
collection
end
-
+
# The page number we are currently on.
def current_page
@query_parser.current_page
end
-
+
# How many records to display on each page, defaults to 20. Sets with :per_page option when performing search.
def per_page
@query_parser.per_page
end
-
+
# The offset for the current page
def offset
@query_parser.offset
end
-
+
# Total number of pages with found results.
def total_pages
(size / per_page.to_f).ceil
end
-
+
# The previous page number. Returns nil if on first page.
def previous_page
current_page > 1 ? (current_page - 1) : nil
end
-
+
# The next page number. Returns nil if on last page.
def next_page
current_page < total_pages ? (current_page + 1): nil
end
-
+
# Xapit::Facet objects matching this search query. See class for details.
def facets
all_facets.select do |facet|
facet.options.size > 0
end
end
-
+
# Xapit::FacetOption objects which are currently applied to search (through :facets option). Use this to
# display the facets which are currently applied.
#
@@ -142,27 +142,27 @@ def applied_facet_options
option
end
end
-
+
# Includes a suggested variation of a term which will get many more results. Returns nil if no suggestion.
- #
+ #
# <% if @articles.spelling_suggestion %>
# Did you mean <%= link_to h(@articles.spelling_suggestion), :overwrite_params => { :keywords => @articles.spelling_suggestion } %>?
# <% end %>
- #
+ #
def spelling_suggestion
@query_parser.spelling_suggestion
end
-
+
# All Xapit::Facet objects, even if they do not include options.
# Usually you'll want to call Collection#facets
def all_facets
@query_parser.member_class.xapit_index_blueprint.facets.map do |facet_blueprint|
Facet.new(facet_blueprint, @query_parser.query, @query_parser.facet_identifiers)
end
end
-
+
private
-
+
# TODO this could use some refactoring
# See issue #11 for why this is so complex.
def fetch_results(options = {})
Oops, something went wrong.

0 comments on commit 4959550

Please sign in to comment.