Skip to content
Browse files

Updated searchlogic to use config.gem

  • Loading branch information...
1 parent 528cec8 commit f652b0eb9d6f4cf802eb9e56e60a1c0b9775c8a4 @binarylogic committed Nov 17, 2008
Showing with 6 additions and 7,265 deletions.
  1. +6 −5 config/environment.rb
  2. +0 −6 vendor/plugins/searchlogic/.gitignore
  3. +0 −228 vendor/plugins/searchlogic/CHANGELOG.rdoc
  4. +0 −20 vendor/plugins/searchlogic/MIT-LICENSE
  5. +0 −123 vendor/plugins/searchlogic/Manifest
  6. +0 −383 vendor/plugins/searchlogic/README.rdoc
  7. +0 −15 vendor/plugins/searchlogic/Rakefile
  8. +0 −6 vendor/plugins/searchlogic/TODO.rdoc
  9. +0 −4 vendor/plugins/searchlogic/examples/README.rdoc
  10. +0 −1 vendor/plugins/searchlogic/init.rb
  11. +0 −89 vendor/plugins/searchlogic/lib/searchlogic.rb
  12. +0 −52 vendor/plugins/searchlogic/lib/searchlogic/active_record/associations.rb
  13. +0 −218 vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb
  14. +0 −172 vendor/plugins/searchlogic/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb
  15. +0 −168 vendor/plugins/searchlogic/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb
  16. +0 −75 vendor/plugins/searchlogic/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb
  17. +0 −159 vendor/plugins/searchlogic/lib/searchlogic/condition/base.rb
  18. +0 −17 vendor/plugins/searchlogic/lib/searchlogic/condition/begins_with.rb
  19. +0 −21 vendor/plugins/searchlogic/lib/searchlogic/condition/blank.rb
  20. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/condition/child_of.rb
  21. +0 −24 vendor/plugins/searchlogic/lib/searchlogic/condition/descendant_of.rb
  22. +0 −17 vendor/plugins/searchlogic/lib/searchlogic/condition/ends_with.rb
  23. +0 −27 vendor/plugins/searchlogic/lib/searchlogic/condition/equals.rb
  24. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/condition/greater_than.rb
  25. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/condition/greater_than_or_equal_to.rb
  26. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/condition/inclusive_descendant_of.rb
  27. +0 −47 vendor/plugins/searchlogic/lib/searchlogic/condition/keywords.rb
  28. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/condition/less_than.rb
  29. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/condition/less_than_or_equal_to.rb
  30. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/condition/like.rb
  31. +0 −21 vendor/plugins/searchlogic/lib/searchlogic/condition/nil.rb
  32. +0 −20 vendor/plugins/searchlogic/lib/searchlogic/condition/not_begin_with.rb
  33. +0 −19 vendor/plugins/searchlogic/lib/searchlogic/condition/not_blank.rb
  34. +0 −20 vendor/plugins/searchlogic/lib/searchlogic/condition/not_end_with.rb
  35. +0 −26 vendor/plugins/searchlogic/lib/searchlogic/condition/not_equal.rb
  36. +0 −20 vendor/plugins/searchlogic/lib/searchlogic/condition/not_have_keywords.rb
  37. +0 −20 vendor/plugins/searchlogic/lib/searchlogic/condition/not_like.rb
  38. +0 −19 vendor/plugins/searchlogic/lib/searchlogic/condition/not_nil.rb
  39. +0 −14 vendor/plugins/searchlogic/lib/searchlogic/condition/sibling_of.rb
  40. +0 −17 vendor/plugins/searchlogic/lib/searchlogic/condition/tree.rb
  41. +0 −484 vendor/plugins/searchlogic/lib/searchlogic/conditions/base.rb
  42. +0 −36 vendor/plugins/searchlogic/lib/searchlogic/conditions/protection.rb
  43. +0 −31 vendor/plugins/searchlogic/lib/searchlogic/config.rb
  44. +0 −289 vendor/plugins/searchlogic/lib/searchlogic/config/helpers.rb
  45. +0 −53 vendor/plugins/searchlogic/lib/searchlogic/config/search.rb
  46. +0 −75 vendor/plugins/searchlogic/lib/searchlogic/core_ext/hash.rb
  47. +0 −310 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/link.rb
  48. +0 −241 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/links.rb
  49. +0 −87 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/remote_link.rb
  50. +0 −72 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/remote_links.rb
  51. +0 −36 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/remote_select.rb
  52. +0 −82 vendor/plugins/searchlogic/lib/searchlogic/helpers/control_types/select.rb
  53. +0 −208 vendor/plugins/searchlogic/lib/searchlogic/helpers/form.rb
  54. +0 −197 vendor/plugins/searchlogic/lib/searchlogic/helpers/utilities.rb
  55. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/absolute.rb
  56. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/acos.rb
  57. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/asin.rb
  58. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/atan.rb
  59. +0 −27 vendor/plugins/searchlogic/lib/searchlogic/modifiers/base.rb
  60. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/ceil.rb
  61. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/char_length.rb
  62. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/cos.rb
  63. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/cot.rb
  64. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/day_of_month.rb
  65. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/day_of_week.rb
  66. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/day_of_year.rb
  67. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/degrees.rb
  68. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/exp.rb
  69. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/floor.rb
  70. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/hex.rb
  71. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/hour.rb
  72. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/log.rb
  73. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/log10.rb
  74. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/log2.rb
  75. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/lower.rb
  76. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/ltrim.rb
  77. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/md5.rb
  78. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/microseconds.rb
  79. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/milliseconds.rb
  80. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/minute.rb
  81. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/month.rb
  82. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/octal.rb
  83. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/radians.rb
  84. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/round.rb
  85. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/rtrim.rb
  86. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/second.rb
  87. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/sign.rb
  88. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/sin.rb
  89. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/square_root.rb
  90. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/tan.rb
  91. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/trim.rb
  92. +0 −15 vendor/plugins/searchlogic/lib/searchlogic/modifiers/upper.rb
  93. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/week.rb
  94. +0 −11 vendor/plugins/searchlogic/lib/searchlogic/modifiers/year.rb
  95. +0 −148 vendor/plugins/searchlogic/lib/searchlogic/search/base.rb
  96. +0 −53 vendor/plugins/searchlogic/lib/searchlogic/search/conditions.rb
  97. +0 −244 vendor/plugins/searchlogic/lib/searchlogic/search/ordering.rb
  98. +0 −121 vendor/plugins/searchlogic/lib/searchlogic/search/pagination.rb
  99. +0 −89 vendor/plugins/searchlogic/lib/searchlogic/search/protection.rb
  100. +0 −31 vendor/plugins/searchlogic/lib/searchlogic/search/searching.rb
  101. +0 −50 vendor/plugins/searchlogic/lib/searchlogic/shared/utilities.rb
  102. +0 −39 vendor/plugins/searchlogic/lib/searchlogic/shared/virtual_classes.rb
  103. +0 −79 vendor/plugins/searchlogic/lib/searchlogic/version.rb
  104. +0 −15 vendor/plugins/searchlogic/test/fixtures/accounts.yml
  105. +0 −3 vendor/plugins/searchlogic/test/fixtures/cats.yml
  106. +0 −3 vendor/plugins/searchlogic/test/fixtures/dogs.yml
  107. +0 −14 vendor/plugins/searchlogic/test/fixtures/orders.yml
  108. +0 −13 vendor/plugins/searchlogic/test/fixtures/user_groups.yml
  109. +0 −36 vendor/plugins/searchlogic/test/fixtures/users.yml
  110. +0 −81 vendor/plugins/searchlogic/test/test_active_record_associations.rb
  111. +0 −93 vendor/plugins/searchlogic/test/test_active_record_base.rb
  112. +0 −52 vendor/plugins/searchlogic/test/test_condition_base.rb
  113. +0 −143 vendor/plugins/searchlogic/test/test_condition_types.rb
  114. +0 −242 vendor/plugins/searchlogic/test/test_conditions_base.rb
  115. +0 −16 vendor/plugins/searchlogic/test/test_conditions_protection.rb
  116. +0 −23 vendor/plugins/searchlogic/test/test_config.rb
  117. +0 −134 vendor/plugins/searchlogic/test/test_helper.rb
  118. +0 −227 vendor/plugins/searchlogic/test/test_search_base.rb
  119. +0 −19 vendor/plugins/searchlogic/test/test_search_conditions.rb
  120. +0 −165 vendor/plugins/searchlogic/test/test_search_ordering.rb
  121. +0 −72 vendor/plugins/searchlogic/test/test_search_pagination.rb
  122. +0 −24 vendor/plugins/searchlogic/test/test_search_protection.rb
  123. +0 −98 vendor/plugins/searchlogic/test_libs/acts_as_tree.rb
  124. +0 −9 vendor/plugins/searchlogic/test_libs/ordered_hash.rb
  125. +0 −14 vendor/plugins/searchlogic/test_libs/rexml_fix.rb
View
11 config/environment.rb
@@ -27,6 +27,7 @@
# config.gem "aws-s3", :lib => "aws/s3"
config.gem "populator", :version => ">=0.2.4"
config.gem "faker", :version => ">=0.3.1"
+ #config.gem "searchlogic"
# Only load the plugins named here, in the order given. By default, all plugins
# in vendor/plugins are loaded in alphabetical order.
@@ -45,11 +46,11 @@
# Run "rake -D time" for a list of tasks for finding time zone names. Uncomment to use default local time.
config.time_zone = 'UTC'
- #if RAILS_ENV == "development" # putting this in environments/development.rb doesn't work, not sure why
- # config.plugin_paths += ["#{RAILS_ROOT}/../../Libs"]
- # config.plugins = [:searchlogic]
- # require "ruby-debug"
- #end
+ if RAILS_ENV == "development" # putting this in environments/development.rb doesn't work, not sure why
+ config.plugin_paths += ["#{RAILS_ROOT}/../../Libs"]
+ config.plugins = [:searchlogic]
+ require "ruby-debug"
+ end
# Your secret key for verifying cookie session data integrity.
# If you change this key, all old sessions will become invalid!
View
6 vendor/plugins/searchlogic/.gitignore
@@ -1,6 +0,0 @@
-.DS_Store
-*.log
-pkg/*
-coverage/*
-doc/*
-benchmarks/*
View
228 vendor/plugins/searchlogic/CHANGELOG.rdoc
@@ -1,228 +0,0 @@
-== 1.5.3 released 2008-10-30
-
-* Removed ilike conditions and let the like condition determine if it should use like or ilike depending on the connection adapter.
-* Fixed bug where the keywords condition was removing foreign characters.
-* Added configuration option for specifying your javascript library, to cut down on the javascript Searchlogic adds into the form helpers
-* Fixed bug with "not" conditions to use sanitize method, like it should, instead of to_conditions.
-* Only pass :distinct option for the count calculation
-* Fixed not_nil and not_blank conditions to use boolean values configuration option.
-
-== 1.5.2 released 2008-10-21
-
-* Added ilike conditions
-* Removed configatron dependency (was accidentally added)
-
-== 1.5.1 released 2008-10-20
-
-* Fixed bug with per_page_links
-* Added "ordering_by" class for per_page_links
-
-== 1.5.0 released 2008-10-20
-
-* Merge array of conditions with or or and where it makes sense. Begins with condition does not make sense to join with and, so instead join with or.
-* Cleaned up html validity so it will pass W3C validators
-* Restructure configuration to be more organized and allow for more configuration options.
-* Added more configuration options, especially for class names.
-
-== 1.4.1 released 2008-10-15
-
-* Extracted english text into configuration to support alternate languages. I18n support.
-* Improved method detection in add_joins to use respond_to? with the private method option set to true
-
-== 1.4.0 released 2008-10-15
-
-* Fixed bug when duping or cloning to copy over instance vars instead of method values
-* Fixed bug with older versions of ActiveRecord and creating an alias method chain on find in AssociationCollection
-* Added modifiers: upper, lower, trim, ltrim, rtrim
-* Added not_nil and not_blank conditions
-* Modified conditions so that table name is a variable, this allows table name to be switched on the fly.
-* Modified auto joins to return symbols instead of SQL. This allows AR to properly merge the joins and ultimately result in proper SQL when performing multiple complex scopes.
-* Fixed conflicts between includes and joins, duplicate joins are not added. Includes are prioritized. This also makes ActiveRecord much more flexible. Now you can cherry pick included associations. And not have to worry about conflicting with joins.
-* Modified ActiveRecord's default behavior to use inner joins with the :joins option. Inner joins impose limitations. When providing this as a "convenience", inner joins do not make sense. The don't allow OR conditions to be across associations, nor does it properly order when an ordering by an association attribute when that association is optional.
-
-== 1.3.5 released 2008-10-08
-
-* Since joins are now strings, AR doesn't know how to merge them properly. So searchlogic now checks which joins to skip over to avoid conflicts.
-
-== 1.3.4 released 2008-10-07
-
-* Fixed method names creation for conditions with modifiers
-* Create local column conditions, incase there are method conflicts. Such as "id".
-* All joins are switched to left outer joins. When search with *any* conditions, inner joins return incorrect results. Also when ordering by an association that allows for blanks, inner joins exclude the records with blank values. Only option is left outer joins.
-* If joins is manually set with a string, treat it as SQL, just like ActiveRecord
-
-== 1.3.3 released 2008-10-03
-
-* Fixed modifiers being double escaped on equals condition
-* Fixed bug when merging conditions with array substitutions
-* Updated blank condition to check if the values is false or not
-* Fixed type for the year modifier in the mysql adapter
-
-== 1.3.2 released 2008-10-03
-
-* Fixed condition to type cast all values in an array
-* Fixed bug to properly set the type for the type cast column
-* Fixed bug to allow conditions on local columns
-* Apparently ActiveRecord 2.2 doesnt remove duplicates on all joins, need to enforce this for ALL versions of ActiveRecord
-* Fixed bug when passing a symbol as the SQL type for condition return types
-* Moved duplicate removal to only apply when searching or calculating from a search object. Anything done in a normal ActiveRecord method should remain untouched and let ActiveRecord handle it. Just like in ActiveRecord if you do a User.all search and pass some :joins, you might get duplicate records. Searchlogic should not change that behavior, unless called from a searchlogic object.
-* Discard meaningless array values when setting a condition.
-* Delete blank strings from mass assignments on conditions.
-
-== 1.3.1 released 2008-10-02
-
-* Fixed bug when requiring a connection adapter that is not present
-* Fixes bug in "not" conditions
-
-== 1.3.0 released 2008-10-02
-
-* Added modifiers into the mix: hour_of_created_at_less_than = 10, etc.
-* Changed how the Searchlogic::Conditions::Base class works. Instead of predefining all methods for all conditions upon instantiation, they are defined as needed via method_missing. Similar to
- ActiveRecord's dynamic finders: User.find_by_name_and_email(name, email). Once the are defined they never hit method_missing again, acts like a cache.
-* Altered how values are handled for each condition, meaningless values are ignored completely.
-* Added in more "not" conditions: not_like, not_begin_with, not_have_keywords, etc
-
-== 1.2.2 released 2008-09-29
-
-* Fixed bug when reverse engineering order to order_by, assumed ASC and DESC would always be present when they are not.
-* False is a meaningful value for some conditions, and false.blank? == true. So instead of using value.blank? to ignore conditions we use meaningless?(value), which returns false if it is false.
-* Fixed aliases for lt, lte, gt, and gte.
-* Fixed bug when writing conditions on associations via a hash with string keys
-* Added Config.remove_duplicates to turn off the "automatic" removing of duplicates if desired.
-* Updated searchlogic_state helper to insert the entire state all at once.
-* Added CSS class "ordering" to order_by_link if the search is being ordered by that.
-
-== 1.2.1 released 2008-09-25
-
-* Fixed problem when determining if an order_by_link is currently being ordered. Just "stringified" both comparable values.
-* Removed default order_by and order_as. They will ONLY have values if you specify how to order, otherwise they are nil.
-* Removed order_as requirement. order_as is optional.
-* Added in deep_merge methods for hash, copied over from ActiveSupport 2.1
-* Improved order by auto joins to be based off of what order_by returns instead of setting it when setting order_by.
-* Added priority_order_by. Useful if you want to order featured products first and then order as usual. See documentation in Searchlogic::Search::Ordering for more info.
-* Added in base64 support for order_by and priority_order_by so that it's value is safe in the URL
-* Added priority_order_by_link
-
-== 1.2.0 released 2008-09-24
-
-* Added searchlogic_params and searchlogic_url helper to use outside of the control type helpers.
-* Added dup and clone methods that work properly for searchlogic objects
-* Fixed bug to remove nil scope values, HABTM likes to add :limit => nil
-* Removed unnecessary build_search methods for associations
-* Removed support for searching with conditions only. This just made things much more complicated when you can accomplish the same thing by starting a new search and only setting conditions.
-* Fixed bug when searching with *any* conditions to use left outer joins instead of inner joins.
-
-== 1.1.3 released 2008-09-23
-
-* Setting a condition to nil removes it if the condition is set to ignore blanks
-* Setting search.conditions = "some sql" will reset ALL conditions. Alternatively search.conditions => {:first_name_contains => "Ben"} will overwrite "some sql". The same goes with search.conditions.first_name_contains = "Ben".
-* Fixed bug with inspect
-* Other small performance enhancements with memoized attributes
-
-== 1.1.2 released 2008-09-22
-
-* Fixed bug with select control types not using :search_obj to determine its select values.
-* Added is_nil and is_blank condition types.
-* "memoized" various attributes for performance enhancements
-* Removed the :order option from calculation options when :order is useless and just slows down query.
-* Switched from using :include to :joins, big performance increase
-
-== 1.1.1 released 2008-09-19
-
-* Fixed typo in "next page" button.
-* Updated valid options for searching and performing calculations, fixed some bugs when searching and performing calculations with advanced options.
-* Fixed bug in ordering where table name was assumed by the hash. Now assumed by the reflection.
-* Added default for per_page, so pagination comes implemented by default
-* On mass assignments blank strings for *any* conditions are ignored. Sometimes blank strings are meaningful for "equals" and "does not equal", those only takes effect if you explicitly call these conditions: search.conditions.name = "". User.new_search(:conditions => {:name => ""}) will be ignored. Also, Searchlogic should never change how ActiveRecord behaves by default. So User.all(:conditions => {:name => ""}) will NOT be ignored.
-
-== 1.1.0 released 2008-09-18
-
-* Added the options :inner_spread and :outer_spread to the page_links helper. Also added various config options for setting page_links defaults.
-* Updated calculation methods to ignore :limit and :offset. AR returns 0 or nil on calculations that provide an offset.
-* Added support to allow for "any" of the conditions, instead of all of them. Joins conditions with "or" instead of "and". See Searchlogic::Conditions::Base or the readme
-
-== 1.0.4 released 2008-09-18
-
-* Fixed bugs when performing calculations and searches on has_many through relationships.
-* Instead of merging the find_options myself, I delegated that to AR's with_scope function, which already does this. Much more solid, less intrusive.
-
-== 1.0.3 released 2008-09-18
-
-* Updated inspect to show the current options for your search. Plays nicer in the console.
-* Made sure protection state is persistent among relationship conditions.
-* Fixed bug with backwards compatibility of rails. concat requires a proc in older version.
-* Defaulted remote control types to use GET requests instead of POST.
-* Completely reengineered integration with ActiveRecord. Searchlogic is properly using scopes letting you do use serachgasm where scope are implemented. @current_users.orders.new_search, etc. If your search is scoped and you want a search object, that search object will represent a new search in the context of those scopes, meaning the scopes get merged into Searchlogic as options.
-* Dropped support for Searchlogic functionality when defining relationships: has_many :order, :conditions => {:total_gt => 100}, will not work anymore. It's a chicken and the egg thing. Searchlogic needs AR constants, some models get loaded before others, therefore the Order model may not have been loaded yet, causing an unknown constant error.
-* Clean up redundant code and moved it into the Searchlogic::Shared namespace.
-
-== 1.0.2 released 2008-09-12
-
-* Moved cached searchers out of the global namespace and into the Searchlogic::Cache namespce.
-* Various changes to improve performance through profiling / benchmarking. http://pastie.org/271936
-* Config.per_page works with new_search & new_search! only. Where as before it was only working if the search was protected.
-
-== 1.0.1 released 2008-09-11
-
-* Cached "searchers" so when a new search object is instantiated it doesn't go through all of the meta programming and method creation. Helps a lot with performance. You will see the speed benefits after the first instantiation.
-* Added in new options for page_links.
-* Fixed minor bugs when doing page_links.
-* Updated documentation to be more detailed and inclusive.
-
-== 1.0.0 released 2008-09-08
-
-* Major changes in the helpers, they were completely re-engineered. Hence the new version. I established a pattern between all helpers giving you complete flexibility as to how they are used. All helpers are called differently now (see documentation).
-
-== 0.9.10 released 2008-09-08
-
-* Fixed bug with setting the per_page configuration to only take effect on protected searches, thus staying out of the way of normal searching.
-* Hardened more tests
-
-== 0.9.9 released 2008-09-07
-
-* Fixed setting per_page to nil, false, or ''. This is done to "show all" results.
-
-== 0.9.8 released 2008-09-06
-
-* Fixed order_by helper bug when guessing the text with arrays. Should use the first value instead of last.
-* Added in per_page config option.
-
-== 0.9.7 released 2008-09-06
-
-* Complete class restructure. Moved the 3 main components into their own base level class: Search, Conditions, Condition
-* Split logic and functionality into their own modules, implemented via alias_chain_method
-* Added in helpers for using in a rails app
-* Added link to documentation and live example in README
-* Various small bug fixes
-* Hardened tests
-
-== 0.9.6 released 2008-09-04
-
-* Fixed bug when instantiating with nil options
-
-== 0.9.5 released 2008-09-03
-
-* Enhanced searching with conditions only, added in search methods and calculations
-* Updated README to include examples
-
-== 0.9.4 released 2008-09-03
-
-* Cleaned up search methods
-* Removed reset! method for both searching and searching by conditions
-
-== 0.9.3 released 2008-09-02
-
-* Changed structure of conditions to have their own class
-* Added API for adding your own conditions.
-
-== 0.9.2 released 2008-09-02
-
-* Enhanced protection from SQL injections (made more efficient)
-
-== 0.9.1 released 2008-09-02
-
-* Added aliases for datetime, date, time, and timestamp attrs. You could call created_at_after, now you can also call created_after. Just removed the "at" requirement.
-
-== 0.9.0 released 2008-09-01
-
-* First release
View
20 vendor/plugins/searchlogic/MIT-LICENSE
@@ -1,20 +0,0 @@
-Copyright (c) 2007 Ben Johnson of Binary Logic (binarylogic.com)
-
-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
-NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
-LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
-OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
-WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
View
123 vendor/plugins/searchlogic/Manifest
@@ -1,123 +0,0 @@
-CHANGELOG.rdoc
-examples/README.rdoc
-init.rb
-lib/searchlogic/active_record/associations.rb
-lib/searchlogic/active_record/base.rb
-lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb
-lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb
-lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb
-lib/searchlogic/condition/base.rb
-lib/searchlogic/condition/begins_with.rb
-lib/searchlogic/condition/blank.rb
-lib/searchlogic/condition/child_of.rb
-lib/searchlogic/condition/descendant_of.rb
-lib/searchlogic/condition/ends_with.rb
-lib/searchlogic/condition/equals.rb
-lib/searchlogic/condition/greater_than.rb
-lib/searchlogic/condition/greater_than_or_equal_to.rb
-lib/searchlogic/condition/inclusive_descendant_of.rb
-lib/searchlogic/condition/keywords.rb
-lib/searchlogic/condition/less_than.rb
-lib/searchlogic/condition/less_than_or_equal_to.rb
-lib/searchlogic/condition/like.rb
-lib/searchlogic/condition/nil.rb
-lib/searchlogic/condition/not_begin_with.rb
-lib/searchlogic/condition/not_blank.rb
-lib/searchlogic/condition/not_end_with.rb
-lib/searchlogic/condition/not_equal.rb
-lib/searchlogic/condition/not_have_keywords.rb
-lib/searchlogic/condition/not_like.rb
-lib/searchlogic/condition/not_nil.rb
-lib/searchlogic/condition/sibling_of.rb
-lib/searchlogic/condition/tree.rb
-lib/searchlogic/conditions/base.rb
-lib/searchlogic/conditions/protection.rb
-lib/searchlogic/config/helpers.rb
-lib/searchlogic/config/search.rb
-lib/searchlogic/config.rb
-lib/searchlogic/core_ext/hash.rb
-lib/searchlogic/helpers/control_types/link.rb
-lib/searchlogic/helpers/control_types/links.rb
-lib/searchlogic/helpers/control_types/remote_link.rb
-lib/searchlogic/helpers/control_types/remote_links.rb
-lib/searchlogic/helpers/control_types/remote_select.rb
-lib/searchlogic/helpers/control_types/select.rb
-lib/searchlogic/helpers/form.rb
-lib/searchlogic/helpers/utilities.rb
-lib/searchlogic/modifiers/absolute.rb
-lib/searchlogic/modifiers/acos.rb
-lib/searchlogic/modifiers/asin.rb
-lib/searchlogic/modifiers/atan.rb
-lib/searchlogic/modifiers/base.rb
-lib/searchlogic/modifiers/ceil.rb
-lib/searchlogic/modifiers/char_length.rb
-lib/searchlogic/modifiers/cos.rb
-lib/searchlogic/modifiers/cot.rb
-lib/searchlogic/modifiers/day_of_month.rb
-lib/searchlogic/modifiers/day_of_week.rb
-lib/searchlogic/modifiers/day_of_year.rb
-lib/searchlogic/modifiers/degrees.rb
-lib/searchlogic/modifiers/exp.rb
-lib/searchlogic/modifiers/floor.rb
-lib/searchlogic/modifiers/hex.rb
-lib/searchlogic/modifiers/hour.rb
-lib/searchlogic/modifiers/log.rb
-lib/searchlogic/modifiers/log10.rb
-lib/searchlogic/modifiers/log2.rb
-lib/searchlogic/modifiers/lower.rb
-lib/searchlogic/modifiers/ltrim.rb
-lib/searchlogic/modifiers/md5.rb
-lib/searchlogic/modifiers/microseconds.rb
-lib/searchlogic/modifiers/milliseconds.rb
-lib/searchlogic/modifiers/minute.rb
-lib/searchlogic/modifiers/month.rb
-lib/searchlogic/modifiers/octal.rb
-lib/searchlogic/modifiers/radians.rb
-lib/searchlogic/modifiers/round.rb
-lib/searchlogic/modifiers/rtrim.rb
-lib/searchlogic/modifiers/second.rb
-lib/searchlogic/modifiers/sign.rb
-lib/searchlogic/modifiers/sin.rb
-lib/searchlogic/modifiers/square_root.rb
-lib/searchlogic/modifiers/tan.rb
-lib/searchlogic/modifiers/trim.rb
-lib/searchlogic/modifiers/upper.rb
-lib/searchlogic/modifiers/week.rb
-lib/searchlogic/modifiers/year.rb
-lib/searchlogic/search/base.rb
-lib/searchlogic/search/conditions.rb
-lib/searchlogic/search/ordering.rb
-lib/searchlogic/search/pagination.rb
-lib/searchlogic/search/protection.rb
-lib/searchlogic/search/searching.rb
-lib/searchlogic/shared/utilities.rb
-lib/searchlogic/shared/virtual_classes.rb
-lib/searchlogic/version.rb
-lib/searchlogic.rb
-Manifest
-MIT-LICENSE
-Rakefile
-README.rdoc
-test/fixtures/accounts.yml
-test/fixtures/cats.yml
-test/fixtures/dogs.yml
-test/fixtures/orders.yml
-test/fixtures/user_groups.yml
-test/fixtures/users.yml
-test/test_active_record_associations.rb
-test/test_active_record_base.rb
-test/test_condition_base.rb
-test/test_condition_types.rb
-test/test_conditions_base.rb
-test/test_conditions_protection.rb
-test/test_config.rb
-test/test_helper.rb
-test/test_search_base.rb
-test/test_search_conditions.rb
-test/test_search_ordering.rb
-test/test_search_pagination.rb
-test/test_search_protection.rb
-test_libs/acts_as_tree.rb
-test_libs/ordered_hash.rb
-test_libs/rexml_fix.rb
-TODO.rdoc
View
383 vendor/plugins/searchlogic/README.rdoc
@@ -1,383 +0,0 @@
-= Searchlogic
-
-Searchlogic is orgasmic. Maybe not orgasmic, but you will get aroused. So go grab a towel and let's dive in.
-
-<b>Searchlogic's inspiration comes right from ActiveRecord. ActiveRecord lets you create objects that represent a record in the database, so why can't you create objects that represent searching the database? Now you can! It's searching, ordering, and pagination all in one.</b>
-
-== Helpful links
-
-* <b>Documentation:</b> http://searchlogic.rubyforge.org
-* <b>Easy pagination, ordering, and searching tutorial:</b> http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchlogic
-* <b>Live example of the tutorial above (with source):</b> http://searchlogic_example.binarylogic.com
-* <b>Bugs / feature suggestions:</b> http://binarylogic.lighthouseapp.com/projects/16601-searchlogic
-
-== Install and use
-
- sudo gem install searchlogic
-
-For rails
-
- $ cd vendor/plugins
- $ sudo gem unpack searchlogic
-
-Or as a plugin
-
- script/plugin install git://github.com/binarylogic/searchlogic.git
-
-Now try out some of the examples below:
-
-<b>For all examples, let's assume the following relationships: User => Orders => Line Items</b>
-
-== Simple Searching Example
-
- User.all(
- :conditions => {
- :first_name_contains => "Ben", # first_name like '%Ben%'
- :email_ends_with => "binarylogic.com", # email like '%binarylogic.com'
- :created_after => Time.now, # created_at > Time.now
- :hour_of_created_at => 5 # HOUR(created_at) > 5 (depends on DB type)
- },
- :per_page => 20, # limit 20
- :page => 3, # offset 40, which starts us on page 3
- :order_as => "ASC",
- :order_by => {:user_group => :name} # order user_groups.name ASC
- )
-
-same as above, but object based
-
- search = User.new_search
- search.conditions.first_name_contains = "Ben"
- search.conditions.email_ends_with = "binarylogic.com"
- search.conditions.created_after = Time.now
- search.conditiona.hour_of_created_at = 5
- search.per_page = 20
- search.page = 3
- search.order_as = "ASC"
- search.order_by = {:user_group => :name}
- search.all
-
-In both examples, instead of using the "all" method you could use any search method: first, find(:all), find(:first), count, sum, average, etc, just like ActiveRecord.
-
-== The beauty of searchlogic, integration into rails
-
-Using Searchlogic in rails is the best part, because rails has all kinds of nifty methods to make dealing with ActiveRecord objects quick and easy, especially with forms. So let's take advantage of them! That's the idea behind this plugin. Searchlogic is searching, ordering, and pagination all rolled into one simple plugin. Take all of that pagination and searching cruft out of your models and controllers, and let Searchlogic handle it. Check it out:
-
- # app/controllers/users_controller.rb
- def index
- @search = User.new_search(params[:search])
- @users, @users_count = @search.all, @search.count
- end
-
-Now your view:
-
- # app/views/users/index.html.haml
- - form_for @search do |f|
- - f.fields_for @search.conditions do |users|
- = users.text_field :first_name_contains
- = users.calendar_date_select :created_after # nice rails plugin for replacing date_select
- - users.fields_for users.object.orders do |orders|
- = orders.select :total_gt, (1..100)
- = f.submit "Search"
-
- - if @users_count > 0
- %table
- %tr
- %th= order_by_link :account => :name
- %th= order_by_link :first_name
- %th= order_by_link :last_name
- %th= order_by_link :email
- - @users.each do |user|
- %tr
- %td= user.account? ? user.account.name : "-"
- %td= user.first_name
- %td= user.last_name
- %td= user.email
-
- Per page:
- = per_page_select
- Page:
- = page_select
- - else
- No users were found.
-
-Things to note in this view:
-
-1. Passing a search object right into form\_for and fields\_for
-2. The built in conditions for each column and how you can traverse the relationships and set conditions on them
-3. The order_by_link helper
-4. The page_select and per_page_select helpers
-5. All of your search logic is in 1 spot: your view. Nice and DRY.
-
-<b>See my tutorial on this example: http://www.binarylogic.com/2008/9/7/tutorial-pagination-ordering-and-searching-with-searchlogic</b>
-
-== Exhaustive Example w/ Object Based Searching (great for form_for or fields_for)
-
- # Start a new search
- @search = User.new_search(
- :conditions => {
- :first_name_contains => "Ben",
- :age_gt => 18,
- :orders => {:total_lt => 100}
- },
- :per_page => 20,
- :page => 2,
- :order_by => {:orders => :total},
- :order_as => "DESC"
- )
-
- # Set local conditions
- @search.conditions.email_ends_with = "binarylogic.com"
-
- # Set conditions on relationships
- @search.conditions.oders.line_items.created_after = Time.now # can traverse through all relationships
-
- # Set options
- @search.per_page = 50 # overrides the 20 set above
- @search.order_by = [:first_name, {:user_group => :name}] # order by first name and then by the user group's name it belongs to
- @search.order_as = "ASC"
-
- # Set ANY of the ActiveRecord options
- @search.group = "last_name"
- @search.readonly = true
- # ... see ActiveRecord documentation
-
- # Return results just like ActiveRecord
- @search.all
- @search.first
-
-Take the @search object and pass it right into form\_for or fields\_for (see above).
-
-== Calculations
-
-Using the object from above:
-
- @search.average('id')
- @search.count # ignores limit and offset
- @search.maximum('id')
- @search.minimum('id')
- @search.sum('id')
- @search.calculate(:sum, 'id')
- # ...any of the above calculations, see ActiveRecord documentation on calculations
-
-Or do it from your model:
-
- User.count(:conditions => {:first_name_contains => "Ben"})
- User.sum('id', :conditions => {:first_name_contains => "Ben"})
- # ... all other calcualtions, etc.
-
-== Different ways to search, take your pick
-
-Any of the options used in the above example can be used in these, but for the sake of brevity I am only using a few:
-
- User.all(:conditions => {:age_gt => 18}, :per_page => 20)
-
- User.first(:conditions => {:age_gt => 18}, :per_page => 20)
-
- User.find(:all, :conditions => {:age_gt => 18}, :per_page => 20)
-
- User.find(:first, :conditions => {:age_gt => 18}, :per_page => 20)
-
- search = User.new_search(:conditions => {:age_gt => 18}) # build_search is an alias
- search.conditions.first_name_contains = "Ben"
- search.per_page = 20
- search.all
-
-== Match ANY or ALL of the conditions
-
-As you saw above, the nice thing about Searchlogic is it's integration with forms. I designed the "any" option so that forms can set this as well, just like a condition.
-
- search = User.new_search(:conditions => {:age_gt => 18})
- search.conditions.first_name_contains = "Ben"
- search.conditions.any = true # can set this to "true" or "1" or "yes"
- search.all # will join all conditions with "or" instead of "and"
- # ... all operations above are available
-
-== Scoped searching
-
- @current_user.orders.find(:all, :conditions => {:total_lte => 500})
- @current_user.orders.count(:conditions => {:total_lte => 500})
- @current_user.orders.sum('total', :conditions => {:total_lte => 500})
-
- search = @current_user.orders.build_search(:conditions => {:total_lte => 500})
-
-== Scope support
-
-Not only can you use searchlogic when searching, but you can use it when using scopes.
-
- class User < ActiveRecord::Base
- named_scope :sexy, :conditions => {:first_name => "Ben", email_ends_with => "binarylogic.com"}, :per_page => 20
- end
-
-or
-
- class User < ActiveRecord::Base
- def self.find_sexy
- with_scope(:find => {:conditions => {:first_name => "Ben", email_ends_with => "binarylogic.com"}, :per_page => 20}) do
- all
- end
- end
- end
-
-== Always use protection...against SQL injections
-
-If there is one thing we all know, it's to always use protection against SQL injections. That's why searchlogic protects you by default. The new\_search methods protect mass assignments by default (instantiation and search.options = {}). This means that various checks are done to ensure it is not possible to perform any type of SQL injection during mass assignments. But this also limits how you can search, meaning you can't write raw SQL. If you want to be daring and search without protection, all that you have to do is add ! to the end of the method: new\_search!.
-
-=== Protected from SQL injections
-
- search = Account.new_search(params[:search])
-
-=== *NOT* protected from SQL injections
-
- accounts = Account.find(params[:search])
- accounts = Account.all(params[:search])
- account = Account.first(params[:search])
- search = Account.new_search!(params[:search])
-
-I'm sure you already knew this, but it's tempting to do this when you can pass the params hash right into these methods.
-
-Lesson learned: use new\_search when passing in params as *ANY* of the options.
-
-== Available Conditions
-
-The conditions are pretty self explanitory, but if you need more information checkout the docs or the source. The code is very simple and self explanatory.
-
-=== Column conditions
-
-Each column can be used with any of the following conditions
-
- Name Aliases Description
- :begins_with :starts_with, :sw, :bw, :start col LIKE 'value%'
- :ends_with :ew, :ends, :end col LIKE '%value'
- :equals :is, "" Lets ActiveRecord handle this
- :greater_than :gt, :after col > value
- :greater_than_or_equal_to :at_least, :least, :gte col >= value
- :ilike :icontains, :ihas PostgreSQL specific, makes LIKE case insensitive
- :less_than :lt, :before col < value
- :less_than_or_equal_to :at_most, :most, :lte col <= value
- :keywords :kwords, :kw Splits into each word and omits meaningless words, a true keyword search
- :like :contains, :has col LIKE '%value%'
-
- :not_begin_with :not_bw, :not_sw, :not_start_with, :not_start, :beginning_is_not, :beginning_not
- :not_end_with :not_ew, :not_end, :end_is_not, :end_not
- :not_equal :does_not_equal, :is_not, :not
- :not_have_keywords :not_have_keywords, :not_keywords, :not_have_kw, :not_kw, :not_have_kwwords, :not_kwwords
- :not_ilike :not_icontain, :not_ihave
- :not_like :not_contain, :not_have
-
-=== Class level conditions
-
-Each model comes preloaded with class level conditions as well. The difference is that these are not applied to each column, but instead to the model as a whole. Example: search.conditions.child_of = 2
-
- Name Description
- :child_of Returns all children of value
- :descendant_of Returns all descendants (children, grandchildren, grandgrandchildren, etc)
- :inclusive_descendant_of Same as above but also includes the root
- :sibling_of Returns all records that have the same parent
-
-== Modifiers
-
-=== What are modifiers?
-
-ActiveRecord does a great job when it comes to keeping your code database agnostic. But I feel like it neglected searching when it came to that goal. What if you want to find all records that were created after 7am? Depending on your database you would have to do something like the following:
-
- MySQL: HOUR(created_at)
- PostgreSQL: date_part('hour', created_at)
- SQLite: strftime('%H', created_at)
-
-All of a sudden your app is not database agnostic. Searchlogic to the rescue! Searchlogic creates what I like to call "modifiers" to handle this nonsense for you. A modifier modifies a column. For example, the hour modifier modifies a datetime column to return the hour.
-
-The last thing to keep in mind is that <b>not all modifiers are available for every database</b>. MySQL and PostgreSQL support all of these, but SQLite does not. SQLite is nice, in the sense that its really is "lite". The only modifiers it supports are the datetime modifiers. If you want support for the other modifiers you have to write the SQLite function yourself and register the modifier in searchlogic.
-
-Here are all of the available modifiers:
-
-=== Available modifiers
-
- Name Aliases Description
- :microsecond :microseconds, :microsecs, :microsec Extracts the microseconds
- :millisecond :milliseconds, :millisecs, :millisec Extracts the milliseconds
- :second :sec Extracts the seconds
- :minute :min Extracts the minute
- :hour Extracts the hour
- :day_of_week :dow Extracts the day of week (1-7)
- :day_of_month :dom Extracts the day of month (1-31)
- :day_of_year :doy Extracts the day of year (1-366)
- :week Extracts the week (1-53), 53rd week can be a "run-over" week to the next year
- :month :mon Extracts the month (1-12)
- :year Extracts the year
-
- :md5 Converts to a MD5
- :char_length :length The length of the string (integer)
- :lower :downcase, :lcase Converts the string to all lower case characters
- :ltrin :lstrip Strips off spaces from the beginning of the string
- :trim :strip Strips off spaces from the beginning and end of the string
- :rtrim :rstrip Strips off spaces from the end of the string
- :upper :upcase, :ucase Converts the string to all upper case character
-
- :absolute :abs The absolute value (-1 => 1)
- :acos The arc cosine
- :asin The arc sine
- :atan The arc tangent
- :ceil :round_up Rounds up to the nearest int
- :cos :cosine The cosine
- :cot :cotangent The cotangent
- :degrees Converts radians to degrees
- :exp :exponential Returns the value of e (the base of natural logarithms) raised to the power of X
- :floor :round_down Rounds down to the nearest int
- :hex Converts the number to a hex
- :log :ln The natural logarithm
- :log10 Returns the base-10 logarithm
- :log2 Returns the base-2 logarithm
- :octal :oct Return an octal representation of a decimal number
- :radians Converts to radians
- :round Rounds the number
- :sign The sign of the number
- :sin The sine of the number
- :square_root :sqrt, :sq_rt The square root of the number
- :tan :tangent The tangent of the number
-
-=== How to use modifiers
-
-Here's what the above table means. Let's take the created_at column. The created_at column is a datetime column, laet's apply modifiers that make sense for a datetime column.
-
- search.conditions.second_of_created_at = 2
- search.conditions.sec_of_created_at_greater_than = 3
- search.conditions.year_of_created_at_most = 5
- search.conditions.year_of_created_at_lt = 2000
- # ... any of the modifiers that apply to datetime columns
-
-Here's the cool part. Chaining modifiers:
-
- search.conditions.ceil_of_cos_of_sec_of_created_at_greater_than = 3
-
-As long as the modifier chain makes sense the possibilities are endless.
-
-=== Modifiers are not indexed
-
-Depending on your database you can create complex indexes. But chances are you probably didn't or don't plan to. So keep in mind that once you use a modifier it will not be using an index, meaning the query will be slower. One of the ways to get the best of both worlds is to cache virtual attributes in the database. Checkout my tutorial:
-
-http://www.binarylogic.com/2008/10/5/tutorial-caching-virtual-attributes-in-the-database
-
-== Roll your own conditions & modifiers
-
-For more information on this please see Searchlogic::Conditions::Base
-
-== Under the hood
-
-I'm a big fan of understanding what I'm using, so here's a quick explanation: The design behind this plugin is pretty simple and I had 1 main rule when developing this:
-
-ActiveRecord should never know about Searchlogic
-
-What that rule means is that any options you pass when searching get "sanitized" down into options ActiveRecord can understand. Searchlogic serves as a transparent filter between you and ActiveRecord. It doesn't dig into the ActiveRecord internals, it only uses what is publicly available. It jumps in and helps out <em>only</em> when needed, otherwise it sits back and stays completely out of the way.
-
-Lastly, Searchlogic is lazy. It only creates objects, methods, and classes when needed. Once it creates them it caches them. For example, all of the nifty conditions are created via meta programming. The first time you execute something like User.new_search all of that method creation gets cached into Searchlogic::Cache::UserSearch. The next time you execute User.new_search it will be over 50 times faster because it uses the cached class.
-
-Between that and the extensive tests, this is a solid and fast plugin.
-
-== Credits
-
-Author: {Ben Johnson}[http://github.com/binarylogic] of {Binary Logic}[http://www.binarylogic.com]
-
-Credit to {Zack Ham}[http://github.com/zackham] for helping with feature suggestions.
-
-
-Copyright (c) 2008 {Ben Johnson}[http://github.com/binarylogic] of {Binary Logic}[http://www.binarylogic.com], released under the MIT license
View
15 vendor/plugins/searchlogic/Rakefile
@@ -1,15 +0,0 @@
-require 'rubygems'
-require 'echoe'
-
-require File.dirname(__FILE__) << "/lib/searchlogic/version"
-
-Echoe.new 'searchlogic' do |p|
- p.version = Searchlogic::Version::STRING
- p.author = "Ben Johnson of Binary Logic"
- p.email = 'bjohnson@binarylogic.com'
- p.project = 'searchlogic'
- p.summary = "Object based ActiveRecord searching, ordering, pagination, and more!"
- p.url = "http://github.com/binarylogic/searchlogic"
- p.dependencies = %w(activerecord activesupport)
- p.include_rakefile = true
-end
View
6 vendor/plugins/searchlogic/TODO.rdoc
@@ -1,6 +0,0 @@
-= To Do
-
-1. Perform "more efficient" checks: year_of_created_at = 2008 and month_of_created_at = 8. Should result in a "BETWEEN" statement utilizing the column indexes. Thanks Georg for letting me know about this.
-2. Solve conflicts between scope joins and joins in the search (for old versions of AR). Also solve conflicts between joins and includes.
-3. Add configuration to change the "english" words
-4. Re-add the distinct option
View
4 vendor/plugins/searchlogic/examples/README.rdoc
@@ -1,4 +0,0 @@
-=== Live example
-
-* Please see the live example: http://searchlogic_example.binarylogic.com
-* Source / Github project for the example: http://github.com/binarylogic/searchlogic_example.binarylogic.com
View
1 vendor/plugins/searchlogic/init.rb
@@ -1 +0,0 @@
-require File.dirname(__FILE__) << "/lib/searchlogic"
View
89 vendor/plugins/searchlogic/lib/searchlogic.rb
@@ -1,89 +0,0 @@
-$:.unshift(File.dirname(__FILE__)) unless $:.include?(File.dirname(__FILE__)) || $:.include?(File.expand_path(File.dirname(__FILE__)))
-
-require "active_support"
-require "active_record"
-require "active_record/version"
-
-["mysql", "postgresql", "sqlite"].each do |adapter_name|
- begin
- require "active_record/connection_adapters/#{adapter_name}_adapter"
- require "searchlogic/active_record/connection_adapters/#{adapter_name}_adapter"
- rescue Exception
- end
-end
-
-# Core Ext
-require "searchlogic/core_ext/hash"
-
-# Shared
-require "searchlogic/shared/utilities"
-require "searchlogic/shared/virtual_classes"
-
-# Base classes
-require "searchlogic/version"
-require "searchlogic/config/helpers"
-require "searchlogic/config/search"
-require "searchlogic/config"
-
-# ActiveRecord
-require "searchlogic/active_record/base"
-require "searchlogic/active_record/associations"
-
-# Search
-require "searchlogic/search/ordering"
-require "searchlogic/search/pagination"
-require "searchlogic/search/conditions"
-require "searchlogic/search/searching"
-require "searchlogic/search/base"
-require "searchlogic/search/protection"
-
-# Conditions
-require "searchlogic/conditions/protection"
-require "searchlogic/conditions/base"
-
-# Condition
-require "searchlogic/condition/base"
-require "searchlogic/condition/tree"
-SEARCHGASM_CONDITIONS = [:begins_with, :blank, :child_of, :descendant_of, :ends_with, :equals, :greater_than, :greater_than_or_equal_to, :inclusive_descendant_of, :like, :nil, :not_begin_with, :not_blank, :not_end_with, :not_equal, :not_have_keywords, :not_nil, :keywords, :less_than, :less_than_or_equal_to, :sibling_of]
-SEARCHGASM_CONDITIONS.each { |condition| require "searchlogic/condition/#{condition}" }
-
-# Modifiers
-require "searchlogic/modifiers/base"
-SEARCHGASM_MODIFIERS = [:absolute, :acos, :asin, :atan, :ceil, :char_length, :cos, :cot, :day_of_month, :day_of_week, :day_of_year, :degrees, :exp, :floor, :hex, :hour, :log, :log10, :log2, :lower, :ltrim, :md5, :microseconds, :milliseconds, :minute, :month, :octal, :radians, :round, :rtrim, :second, :sign, :sin, :square_root, :tan, :trim, :upper, :week, :year]
-SEARCHGASM_MODIFIERS.each { |modifier| require "searchlogic/modifiers/#{modifier}" }
-
-# Helpers
-require "searchlogic/helpers/utilities"
-require "searchlogic/helpers/form"
-require "searchlogic/helpers/control_types/link"
-require "searchlogic/helpers/control_types/links"
-require "searchlogic/helpers/control_types/select"
-require "searchlogic/helpers/control_types/remote_link"
-require "searchlogic/helpers/control_types/remote_links"
-require "searchlogic/helpers/control_types/remote_select"
-
-# Lets do it!
-module Searchlogic
- module Search
- class Base
- include Conditions
- include Ordering
- include Protection
- include Pagination
- include Searching
- end
- end
-
- module Conditions
- class Base
- include Protection
- end
-
- SEARCHGASM_CONDITIONS.each { |condition| Base.register_condition("Searchlogic::Condition::#{condition.to_s.camelize}".constantize) }
- SEARCHGASM_MODIFIERS.each { |modifier| Base.register_modifier("Searchlogic::Modifiers::#{modifier.to_s.camelize}".constantize) }
- end
-
- # The namespace I put all cached search classes.
- module Cache
- end
-end
View
52 vendor/plugins/searchlogic/lib/searchlogic/active_record/associations.rb
@@ -1,52 +0,0 @@
-module Searchlogic
- module ActiveRecord
- # = Searchlogic ActiveRecord Associations
- #
- # These methods hook into ActiveRecords association methods and add in searchlogic functionality.
- module Associations
- module AssociationCollection
- # This needs to be implemented because AR doesn't leverage scopes with this method like it probably should
- def find_with_searchlogic(*args)
- options = args.extract_options!
- args << filter_options_with_searchlogic(options)
- find_without_searchlogic(*args)
- end
- end
-
- module HasManyAssociation
- def count_with_searchlogic(*args)
- options = args.extract_options!
- args << filter_options_with_searchlogic(options)
- count_without_searchlogic(*args)
- end
- end
- end
- end
-end
-
-ActiveRecord::Associations::AssociationCollection.class_eval do
- if respond_to?(:find)
- include Searchlogic::ActiveRecord::Associations::AssociationCollection
- alias_method_chain :find, :searchlogic
- end
-end
-
-ActiveRecord::Associations::HasManyAssociation.class_eval do
- include Searchlogic::ActiveRecord::Associations::HasManyAssociation
- alias_method_chain :count, :searchlogic
-
- # Older versions of AR have find in here, not in AssociationCollection
- include Searchlogic::ActiveRecord::Associations::AssociationCollection
- alias_method_chain :find, :searchlogic
-end
-
-ActiveRecord::Associations::ClassMethods::InnerJoinDependency::InnerJoinAssociation.class_eval do
- private
- # Inner joins impose limitations on queries. They can be quicker but you can't do OR conditions when conditions
- # overlap from the base model to any of its associations. Also, inner joins won't allow you to order by an association
- # attribute. What if the association is optional? All of those records are ommitted. It just doesn't make sense to default
- # to inner joins when providing this as a "convenience" when searching. So let's change it.
- def join_type
- "LEFT OUTER JOIN"
- end
-end
View
218 vendor/plugins/searchlogic/lib/searchlogic/active_record/base.rb
@@ -1,218 +0,0 @@
-module Searchlogic
- # == Searchlogic ActiveRecord
- #
- # Hooks into ActiveRecord to add all of the searchlogic functionality into your models. Only uses what is publically available, doesn't dig into internals, and
- # searchlogic only gets involved when needed.
- module ActiveRecord
- # = Searchlogic ActiveRecord Base
- # Adds in base level functionality to ActiveRecord
- module Base
- # This is an alias method chain. It hook into ActiveRecord's "calculate" method and checks to see if Searchlogic should get involved.
- def calculate_with_searchlogic(*args)
- options = args.extract_options!
- options = filter_options_with_searchlogic(options, false)
- args << options
- calculate_without_searchlogic(*args)
- end
-
- # This is an alias method chain. It hooks into ActiveRecord's "find" method and checks to see if Searchlogic should get involved.
- def find_with_searchlogic(*args)
- options = args.extract_options!
- options = filter_options_with_searchlogic(options)
- args << options
- find_without_searchlogic(*args)
- end
-
- # This is an alias method chain. It hooks into ActiveRecord's scopes and checks to see if Searchlogic should get involved. Allowing you to use all of Searchlogics conditions and tools
- # in scopes as well.
- #
- # === Examples
- #
- # Named scopes:
- #
- # named_scope :top_expensive, :conditions => {:total_gt => 1_000_000}, :per_page => 10
- # named_scope :top_expensive_ordered, :conditions => {:total_gt => 1_000_000}, :per_page => 10, :order_by => {:user => :first_name}
- #
- # Good ole' regular scopes:
- #
- # with_scope(:find => {:conditions => {:total_gt => 1_000_000}, :per_page => 10}) do
- # find(:all)
- # end
- #
- # with_scope(:find => {:conditions => {:total_gt => 1_000_000}, :per_page => 10}) do
- # build_search
- # end
- def with_scope_with_searchlogic(method_scoping = {}, action = :merge, &block)
- method_scoping[:find] = filter_options_with_searchlogic(method_scoping[:find]) if method_scoping[:find]
- with_scope_without_searchlogic(method_scoping, action, &block)
- end
-
- # This is a special method that Searchlogic adds in. It returns a new search object on the model. So you can search via an object.
- #
- # <b>This method is "protected". Meaning it checks the passed options for SQL injections. So trying to write raw SQL in *any* of the option will result in a raised exception. It's safe to pass a params object when instantiating.</b>
- #
- # This method has an alias "new_search"
- #
- # === Examples
- #
- # search = User.new_search
- # search.conditions.first_name_contains = "Ben"
- # search.per_page = 20
- # search.page = 2
- # search.order_by = {:user_group => :name}
- # search.all # can call any search method: first, find(:all), find(:first), sum("id"), etc...
- def build_search(options = {}, &block)
- search = searchlogic_search
- search.protect = true
- search.options = options
- yield search if block_given?
- search
- end
-
- # See build_search. This is the same method but *without* protection. Do *NOT* pass in a params object to this method.
- #
- # This also has an alias "new_search!"
- def build_search!(options = {}, &block)
- search = searchlogic_search(options)
- yield search if block_given?
- search
- end
-
- # Similar to ActiveRecord's attr_protected, but for conditions. It will block any conditions in this array that are being mass assigned. Mass assignments are:
- #
- # === Examples
- #
- # search = User.new_search(:conditions => {:first_name_like => "Ben", :email_contains => "binarylogic.com"})
- # search.options = {:conditions => {:first_name_like => "Ben", :email_contains => "binarylogic.com"}}
- #
- # If first_name_like is in the list of conditions_protected then it will be removed from the hash.
- def conditions_protected(*conditions)
- write_inheritable_attribute(:conditions_protected, Set.new(conditions.map(&:to_s)) + (protected_conditions || []))
- end
-
- def protected_conditions # :nodoc:
- read_inheritable_attribute(:conditions_protected)
- end
-
- # This is the reverse of conditions_protected. You can specify conditions here and *only* these conditions will be allowed in mass assignment. Any condition not specified here will be blocked.
- def conditions_accessible(*conditions)
- write_inheritable_attribute(:conditions_accessible, Set.new(conditions.map(&:to_s)) + (accessible_conditions || []))
- end
-
- def accessible_conditions # :nodoc:
- read_inheritable_attribute(:conditions_accessible)
- end
-
- private
- def filter_options_with_searchlogic(options = {}, searching = true)
- return options unless Searchlogic::Search::Base.needed?(self, options)
- search = Searchlogic::Search::Base.create_virtual_class(self).new # call explicitly to avoid merging the scopes into the search
- search.acting_as_filter = true
- search.scope = scope(:find)
- conditions = options.delete(:conditions) || options.delete("conditions") || {}
- if conditions
- case conditions
- when Hash
- conditions.each { |condition, value| search.conditions.send("#{condition}=", value) } # explicitly call to enforce blanks
- else
- search.conditions = conditions
- end
- end
- search.options = options
- search.sanitize(searching)
- end
-
- def searchlogic_search(options = {})
- scope = {}
- current_scope = scope(:find) && scope(:find).deep_dup
- if current_scope
- [:conditions, :include, :joins].each do |option|
- value = current_scope.delete(option)
- next if value.blank?
- scope[option] = value
- end
-
- # Delete nil values in the scope, for some reason habtm relationships like to pass :limit => nil
- new_scope = {}
- current_scope.each { |k, v| new_scope[k] = v unless v.nil? }
- current_scope = new_scope
- end
- search = Searchlogic::Search::Base.create_virtual_class(self).new
- search.scope = scope
- search.options = current_scope
- search.options = options
- search
- end
- end
- end
-end
-
-ActiveRecord::Base.send(:extend, Searchlogic::ActiveRecord::Base)
-
-module ActiveRecord #:nodoc: all
- class Base
- class << self
- alias_method_chain :calculate, :searchlogic
- alias_method_chain :find, :searchlogic
- alias_method_chain :with_scope, :searchlogic
- alias_method :new_search, :build_search
- alias_method :new_search!, :build_search!
-
- def valid_find_options
- VALID_FIND_OPTIONS
- end
-
- def valid_calculations_options
- Calculations::CALCULATIONS_OPTIONS
- end
-
- private
- # This is copied over from 2 different versions of ActiveRecord. I have to do this in order to preserve the "auto joins"
- # as symbols. Keeping them as symbols allows ActiveRecord to merge them properly. The problem is when they conflict with includes.
- # Includes add joins also, and they add them before joins do. So if they already added them skip them. Now you can do queries like:
- #
- # User.all(:joins => {:orders => :line_items}, :include => :orders)
- #
- # Where as before, the only way to get the above query to work would be to include line_items also, which is not neccessarily what you want.
- def add_joins!(sql, options_or_joins, scope = :auto) # :nodoc:
- code_type = (respond_to?(:array_of_strings?, true) && :array_of_strings) || (respond_to?(:merge_joins, true) && :merge_joins)
-
- case code_type
- when :array_of_strings, :merge_joins
- joins = options_or_joins
- scope = scope(:find) if :auto == scope
- merged_joins = scope && scope[:joins] && joins ? merge_joins(scope[:joins], joins) : (joins || scope && scope[:joins])
- case merged_joins
- when Symbol, Hash, Array
- if code_type == :array_of_strings && array_of_strings?(merged_joins)
- merged_joins.each { |merged_join| sql << " #{merged_join} " unless sql.include?(merged_join) }
- else
- join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, merged_joins, nil)
- join_dependency.join_associations.each do |assoc|
- join_sql = assoc.association_join
- sql << " #{join_sql} " unless sql.include?(join_sql)
- end
- end
- when String
- sql << " #{merged_joins} " if merged_joins && !sql.include?(merged_joins)
- end
- else
- options = options_or_joins
- scope = scope(:find) if :auto == scope
- [(scope && scope[:joins]), options[:joins]].each do |join|
- case join
- when Symbol, Hash, Array
- join_dependency = ActiveRecord::Associations::ClassMethods::InnerJoinDependency.new(self, join, nil)
- join_dependency.join_associations.each do |assoc|
- join_sql = assoc.association_join
- sql << " #{join_sql} " unless sql.include?(join_sql)
- end
- else
- sql << " #{join} " if join && !sql.include?(join)
- end
- end
- end
- end
- end
- end
-end
View
172 ...or/plugins/searchlogic/lib/searchlogic/active_record/connection_adapters/mysql_adapter.rb
@@ -1,172 +0,0 @@
-module Searchlogic
- module ActiveRecord
- module ConnectionAdapters # :nodoc: all
- module MysqlAdapter
- # Date / time functions
- def microseconds_sql(column_name)
- "MICROSECOND(#{column_name})"
- end
-
- def milliseconds_sql(column_name)
- "(MICROSECOND(#{column_name}) / 1000)"
- end
-
- def second_sql(column_name)
- "SECOND(#{column_name})"
- end
-
- def minute_sql(column_name)
- "MINUTE(#{column_name})"
- end
-
- def hour_sql(column_name)
- "HOUR(#{column_name})"
- end
-
- def day_of_week_sql(column_name)
- "DAYOFWEEK(#{column_name})"
- end
-
- def day_of_month_sql(column_name)
- "DAYOFMONTH(#{column_name})"
- end
-
- def day_of_year_sql(column_name)
- "DAYOFYEAR(#{column_name})"
- end
-
- def week_sql(column_name)
- "WEEK(#{column_name}, 2)"
- end
-
- def month_sql(column_name)
- "MONTH(#{column_name})"
- end
-
- def year_sql(column_name)
- "YEAR(#{column_name})"
- end
-
- # String functions
- def char_length_sql(column_name)
- "CHAR_LENGTH(#{column_name})"
- end
-
- def lower_sql(column_name)
- "LOWER(#{column_name})"
- end
-
- def ltrim_sql(column_name)
- "LTRIM(#{column_name})"
- end
-
- def md5_sql(column_name)
- "MD5(#{column_name})"
- end
-
- def rtrim_sql(column_name)
- "RTRIM(#{column_name})"
- end
-
- def trim_sql(column_name)
- "TRIM(#{column_name})"
- end
-
- def upper_sql(column_name)
- "UPPER(#{column_name})"
- end
-
- # Number functions
- def absolute_sql(column_name)
- "ABS(#{column_name})"
- end
-
- def acos_sql(column_name)
- "ACOS(#{column_name})"
- end
-
- def asin_sql(column_name)
- "ASIN(#{column_name})"
- end
-
- def atan_sql(column_name)
- "ATAN(#{column_name})"
- end
-
- def ceil_sql(column_name)
- "CEIL(#{column_name})"
- end
-
- def cos_sql(column_name)
- "COS(#{column_name})"
- end
-
- def cot_sql(column_name)
- "COT(#{column_name})"
- end
-
- def degrees_sql(column_name)
- "DEGREES(#{column_name})"
- end
-
- def exp_sql(column_name)
- "EXP(#{column_name})"
- end
-
- def floor_sql(column_name)
- "FLOOR(#{column_name})"
- end
-
- def hex_sql(column_name)
- "HEX(#{column_name})"
- end
-
- def ln_sql(column_name)
- "LN(#{column_name})"
- end
-
- def log_sql(column_name)
- "LOG(#{column_name})"
- end
-
- def log2_sql(column_name)
- "LOG2(#{column_name})"
- end
-
- def log10_sql(column_name)
- "LOG10(#{column_name})"
- end
-
- def octal_sql(column_name)
- "OCT(#{column_name})"
- end
-
- def radians_sql(column_name)
- "RADIANS(#{column_name})"
- end
-
- def round_sql(column_name)
- "ROUND(#{column_name})"
- end
-
- def sign_sql(column_name)
- "SIGN(#{column_name})"
- end
-
- def sin_sql(column_name)
- "SIN(#{column_name})"
- end
-
- def square_root_sql(column_name)
- "SQRT(#{column_name})"
- end
-
- def tan_sql(column_name)
- "TAN(#{column_name})"
- end
- end
- end
- end
-end
-
-::ActiveRecord::ConnectionAdapters::MysqlAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::MysqlAdapter)
View
168 ...ugins/searchlogic/lib/searchlogic/active_record/connection_adapters/postgresql_adapter.rb
@@ -1,168 +0,0 @@
-module Searchlogic
- module ActiveRecord
- module ConnectionAdapters
- module PostgreSQLAdapter
- # Datetime functions
- def microseconds_sql(column_name)
- "date_part('microseconds', #{column_name})"
- end
-
- def milliseconds_sql(column_name)
- "date_part('milliseconds', #{column_name})"
- end
-
- def second_sql(column_name)
- "date_part('second', #{column_name})"
- end
-
- def minute_sql(column_name)
- "date_part('minute', #{column_name})"
- end
-
- def hour_sql(column_name)
- "date_part('hour', #{column_name})"
- end
-
- def day_of_week_sql(column_name)
- "(date_part('dow', #{column_name}) + 1)"
- end
-
- def day_of_month_sql(column_name)
- "date_part('day', #{column_name})"
- end
-
- def day_of_year_sql(column_name)
- "date_part('doy', #{column_name})"
- end
-
- def week_sql(column_name)
- "date_part('week', #{column_name})"
- end
-
- def month_sql(column_name)
- "date_part('month', #{column_name})"
- end
-
- def year_sql(column_name)
- "date_part('year', #{column_name})"
- end
-
- # String functions
- def char_length_sql(column_name)
- "length(#{column_name})"
- end
-
- def lower_sql(column_name)
- "lower(#{column_name})"
- end
-
- def ltrim_sql(column_name)
- "ltrim(#{column_name})"
- end
-
- def md5_sql(column_name)
- "md5(#{column_name})"
- end
-
- def rtrim_sql(column_name)
- "rtrim(#{column_name})"
- end
-
- def trim_sql(column_name)
- "trim(#{column_name})"
- end
-
- def upper_sql(column_name)
- "upper(#{column_name})"
- end
-
- # Number functions
- def absolute_sql(column_name)
- "abs(#{column_name})"
- end
-
- def acos_sql(column_name)
- "acos(#{column_name})"
- end
-
- def asin_sql(column_name)
- "asin(#{column_name})"
- end
-
- def atan_sql(column_name)
- "atan(#{column_name})"
- end
-
- def ceil_sql(column_name)
- "ceil(#{column_name})"
- end
-
- def cos_sql(column_name)
- "cos(#{column_name})"
- end
-
- def cot_sql(column_name)
- "cot(#{column_name})"
- end
-
- def degrees_sql(column_name)
- "degrees(#{column_name})"
- end
-
- def exp_sql(column_name)
- "exp(#{column_name})"
- end
-
- def floor_sql(column_name)
- "floor(#{column_name})"
- end
-
- def hex_sql(column_name)
- "to_hex(#{column_name})"
- end
-
- def ln_sql(column_name)
- "ln(#{column_name})"
- end
-
- def log_sql(column_name)
- "log(#{column_name})"
- end
-
- def log2_sql(column_name)
- "log(2.0, #{column_name})"
- end
-
- def log10_sql(column_name)
- "log(10.0, #{column_name})"
- end
-
- def radians_sql(column_name)
- "radians(#{column_name})"
- end
-
- def round_sql(column_name)
- "round(#{column_name})"
- end
-
- def sign_sql(column_name)
- "sign(#{column_name})"
- end
-
- def sin_sql(column_name)
- "sin(#{column_name})"
- end
-
- def square_root_sql(column_name)
- "sqrt(#{column_name})"
- end
-
- def tan_sql(column_name)
- "tan(#{column_name})"
- end
- end
- end
- end
-end
-
-::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::PostgreSQLAdapter)
View
75 ...r/plugins/searchlogic/lib/searchlogic/active_record/connection_adapters/sqlite_adapter.rb
@@ -1,75 +0,0 @@
-module Searchlogic
- module ActiveRecord
- module ConnectionAdapters
- module SQLiteAdapter
- # Date functions
- def microseconds_sql(column_name)
- "((strftime('%f', #{column_name}) % 1) * 1000000)"
- end
-
- def milliseconds_sql(column_name)
- "((strftime('%f', #{column_name}) % 1) * 1000)"
- end
-
- def second_sql(column_name)
- "strftime('%S', #{column_name})"
- end
-
- def minute_sql(column_name)
- "strftime('%M', #{column_name})"
- end
-
- def hour_sql(column_name)
- "strftime('%H', #{column_name})"
- end
-
- def day_of_week_sql(column_name)
- "strftime('%w', #{column_name})"
- end
-
- def day_of_month_sql(column_name)
- "strftime('%d', #{column_name})"
- end
-
- def day_of_year_sql(column_name)
- "strftime('%j', #{column_name})"
- end
-
- def week_sql(column_name)
- "strftime('%W', #{column_name})"
- end
-
- def month_sql(column_name)
- "strftime('%m', #{column_name})"
- end
-
- def year_sql(column_name)
- "strftime('%Y', #{column_name})"
- end
-
- # String functions
- def lower_sql(column_name)
- "lower(#{column_name})"
- end
-
- def ltrim_sql(column_name)
- "ltrim(#{column_name})"
- end
-
- def rtrim_sql(column_name)
- "rtrim(#{column_name})"
- end
-
- def trim_sql(column_name)
- "trim(#{column_name})"
- end
-
- def upper_sql(column_name)
- "upper(#{column_name})"
- end
- end
- end
- end
-end
-
-::ActiveRecord::ConnectionAdapters::SQLiteAdapter.send(:include, Searchlogic::ActiveRecord::ConnectionAdapters::SQLiteAdapter)
View
159 vendor/plugins/searchlogic/lib/searchlogic/condition/base.rb
@@ -1,159 +0,0 @@
-module Searchlogic
- module Condition # :nodoc:
- # = Conditions condition
- #
- # The base class for creating a condition. Your custom conditions should extend this class.
- # See Searchlogic::Conditions::Base.register_condition on how to write your own condition.
- class Base
- include Shared::Utilities
-
- attr_accessor :column, :column_for_type_cast, :column_sql, :column_sql_format, :klass, :table_name
- class_inheritable_accessor :handle_array_value, :ignore_meaningless_value, :join_arrays_with_or, :value_type
- self.ignore_meaningless_value = true
-
- class << self
- # Name of the condition type inferred from the class name
- def condition_type_name
- name.split("::").last.underscore
- end
-
- def handle_array_value?
- handle_array_value == true
- end
-
- def ignore_meaningless_value? # :nodoc:
- ignore_meaningless_value == true
- end
-
- def join_arrays_with_or?
- join_arrays_with_or == true
- end
-
- # Determines what to call the condition for the model
- #
- # Searchlogic tries to create conditions on each model. Before it does this it passes the model to this method to see what to call the condition. If the condition type doesnt want to create a condition on
- # a model it will just return nil and Searchlogic will skip over it.
- def condition_names_for_model
- []
- end
-
- # Same as condition_name_for_model, but for a model's column obj
- def condition_names_for_column
- [condition_type_name]
- end
- end
-
- def initialize(klass, options = {})
- self.klass = klass
- self.table_name = options[:table_name] || klass.table_name
-
- if options[:column]
- self.column = options[:column].class < ::ActiveRecord::ConnectionAdapters::Column ? options[:column] : klass.columns_hash[options[:column].to_s]
-
- if options[:column_for_type_cast]
- self.column_for_type_cast = options[:column_for_type_cast]
- else
- type = (!self.class.value_type.blank? && self.class.value_type.to_s) || (!options[:column_type].blank? && options[:column_type].to_s) || column.sql_type
- self.column_for_type_cast = column.class.new(column.name, column.default.to_s, type, column.null)
- end
-
- self.column_sql_format = options[:column_sql_format] || "{table}.{column}"
- end
- end
-
- # Substitutes string vars with table and column name. Allows us to switch the column and table on the fly and have the condition update appropriately.
- # The table name could be variable depending on the condition. Take STI and more than one child model is used in the condition, the first gets the parent table name, the rest get aliases.
- def column_sql
- column_sql_format.gsub("{table}", quoted_table_name).gsub("{column}", quoted_column_name)
- end
-
- # Allows nils to be meaninful values
- def explicitly_set_value=(value)
- @explicitly_set_value = value
- end
-
- # Need this if someone wants to actually use nil in a meaningful way
- def explicitly_set_value?
- @explicitly_set_value == true
- end
-
- def options
- {:table_name => table_name, :column => column, :column_for_type_cast => column_for_type_cast, :column_sql_format => column_sql_format}
- end
-
- # You should refrain from overwriting this method, it performs various tasks before callign your to_conditions method, allowing you to keep to_conditions simple.
- def sanitize(alt_value = nil) # :nodoc:
- return if value_is_meaningless?
- v = alt_value || value
- if v.is_a?(Array) && !self.class.handle_array_value?
- merge_conditions(*v.collect { |i| sanitize(i) } << {:any => self.class.join_arrays_with_or?})
- else
- v = v.utc if column && v.respond_to?(:utc) && [:time, :timestamp, :datetime].include?(column.type) && klass.time_zone_aware_attributes && !klass.skip_time_zone_conversion_for_attributes.include?(column.name.to_sym)
- to_conditions(v)
- end
- end
-
- # The value for the condition
- def value
- @casted_value ||= type_cast_value(@value)
- end
-
- # Sets the value for the condition
- def value=(v)
- self.explicitly_set_value = true
- @casted_value = nil
- @value = v
- end
-
- def value_is_meaningless? # :nodoc:
- meaningless?(@value)
- end
-
- private
- def like_condition_name
- @like_condition_name ||= klass.connection.adapter_name == "PostgreSQL" ? "ILIKE" : "LIKE"
- end
-
- def meaningless?(v)
- case v
- when Array
- v.each { |i| return false unless meaningless?(i) }
- true
- else
- !explicitly_set_value? || (self.class.ignore_meaningless_value? && v != false && v.blank?)
- end
- end
-
- def meaningful?(v)
- !meaningless?(v)
- end
-
- def quote_column_name(column_name)
- klass.connection.quote_column_name(column_name)
- end
-
- def quoted_column_name
- quote_column_name(column.name)
- end
-
- def quote_table_name(table_name)
- klass.connection.quote_table_name(table_name)
- end
-
- def quoted_table_name
- quote_table_name(table_name)
- end
-
- def type_cast_value(v)
- case v
- when Array
- v.collect { |i| type_cast_value(i) }.compact
- else
- return if meaningless?(v)
- return v if !column_for_type_cast || !v.is_a?(String)
- column_for_type_cast.type_cast(v)
- end
- end
- end
- end
-end
View
17 vendor/plugins/searchlogic/lib/searchlogic/condition/begins_with.rb
@@ -1,17 +0,0 @@
-module Searchlogic
- module Condition
- class BeginsWith < Base
- self.join_arrays_with_or = true
-
- class << self
- def condition_names_for_column
- super + ["bw", "sw", "starts_with", "start"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} LIKE ?", "#{value}%"]
- end
- end
- end
-end
View
21 vendor/plugins/searchlogic/lib/searchlogic/condition/blank.rb
@@ -1,21 +0,0 @@
-module Searchlogic
- module Condition
- class Blank < Base
- self.value_type = :boolean
-
- class << self
- def condition_names_for_column
- super + ["is_blank"]
- end
- end
-
- def to_conditions(value)
- if value == true
- "#{column_sql} IS NULL or #{column_sql} = '' or #{column_sql} = false"
- elsif value == false
- "#{column_sql} IS NOT NULL and #{column_sql} != '' and #{column_sql} != false"
- end
- end
- end
- end
-end
View
11 vendor/plugins/searchlogic/lib/searchlogic/condition/child_of.rb
@@ -1,11 +0,0 @@
-module Searchlogic
- module Condition
- class ChildOf < Tree
- def to_conditions(value)
- parent_association = klass.reflect_on_association(:parent)
- foreign_key_name = (parent_association && parent_association.options[:foreign_key]) || "parent_id"
- ["#{quoted_table_name}.#{quote_column_name(foreign_key_name)} = ?", (value.is_a?(klass) ? value.send(klass.primary_key) : value)]
- end
- end
- end
-end
View
24 vendor/plugins/searchlogic/lib/searchlogic/condition/descendant_of.rb
@@ -1,24 +0,0 @@
-module Searchlogic
- module Condition
- class DescendantOf < Tree
- def to_conditions(value)
- # Wish I knew how to do this in SQL
- root = (value.is_a?(klass) ? value : klass.find(value)) rescue return
- strs = []
- subs = []
- all_children_ids(root).each do |child_id|
- strs << "#{quoted_table_name}.#{quote_column_name(klass.primary_key)} = ?"
- subs << child_id
- end
- [strs.join(" OR "), *subs]
- end
-
- private
- def all_children_ids(record)
- ids = record.children.collect { |child| child.send(klass.primary_key) }
- record.children.each { |child| ids += all_children_ids(child) }
- ids
- end
- end
- end
-end
View
17 vendor/plugins/searchlogic/lib/searchlogic/condition/ends_with.rb
@@ -1,17 +0,0 @@
-module Searchlogic
- module Condition
- class EndsWith < Base
- self.join_arrays_with_or = true
-
- class << self
- def condition_names_for_column
- super + ["ew", "ends", "end"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} LIKE ?", "%#{value}"]
- end
- end
- end
-end
View
27 vendor/plugins/searchlogic/lib/searchlogic/condition/equals.rb
@@ -1,27 +0,0 @@
-module Searchlogic
- module Condition
- class Equals < Base
- self.handle_array_value = true
- self.ignore_meaningless_value = false
-
- class << self
- def condition_names_for_column
- super + ["", "is"]
- end
- end
-
- def to_conditions(value)
- # Let ActiveRecord handle this
- args = []
- case value
- when Range
- args = [value.first, value.last]
- else
- args << value
- end
-
- ["#{column_sql} #{klass.send(:attribute_condition, value)}", *args]
- end
- end
- end
-end
View
15 vendor/plugins/searchlogic/lib/searchlogic/condition/greater_than.rb
@@ -1,15 +0,0 @@
-module Searchlogic
- module Condition
- class GreaterThan < Base
- class << self
- def condition_names_for_column
- super + ["gt", "after"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} > ?", value]
- end
- end
- end
-end
View
15 vendor/plugins/searchlogic/lib/searchlogic/condition/greater_than_or_equal_to.rb
@@ -1,15 +0,0 @@
-module Searchlogic
- module Condition
- class GreaterThanOrEqualTo < Base
- class << self
- def condition_names_for_column
- super + ["gte", "at_least", "least"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} >= ?", value]
- end
- end
- end
-end
View
11 vendor/plugins/searchlogic/lib/searchlogic/condition/inclusive_descendant_of.rb
@@ -1,11 +0,0 @@
-module Searchlogic
- module Condition
- class InclusiveDescendantOf < Tree
- def to_conditions(value)
- condition = DescendantOf.new(klass, options)
- condition.value = value
- merge_conditions(["#{quoted_table_name}.#{quote_column_name(klass.primary_key)} = ?", (value.is_a?(klass) ? value.send(klass.primary_key) : value)], condition.sanitize, :any => true)
- end
- end
- end
-end
View
47 vendor/plugins/searchlogic/lib/searchlogic/condition/keywords.rb
@@ -1,47 +0,0 @@
-module Searchlogic
- module Condition
- class Keywords < Base
- # Because be default it joins with AND, so padding an array just gives you more options. Joining with and is no different than combining all of the words.
- self.join_arrays_with_or = true
-
- BLACKLISTED_WORDS = ('a'..'z').to_a + ["about", "an", "are", "as", "at", "be", "by", "com", "de", "en", "for", "from", "how", "in", "is", "it", "la", "of", "on", "or", "that", "the", "the", "this", "to", "und", "was", "what", "when", "where", "who", "will", "with", "www"] # from ranks.nl
- FOREIGN_CHARACTERS = 'àáâãäåßéèêëìíîïñòóôõöùúûüýÿ'
-
- class << self
- def condition_names_for_column
- super + ["kwords", "kw"]
- end
- end
-
- def to_conditions(value)
- strs = []
- subs = []
-
- search_parts = value.gsub(/,/, " ").split(/ /)
- replace_non_alnum_characters!(search_parts)
- search_parts.uniq!
- remove_blacklisted_words!(search_parts)
- return if search_parts.blank?
-
- search_parts.each do |search_part|
- strs << "#{column_sql} #{like_condition_name} ?"
- subs << "%#{search_part}%"
- end
-
- [strs.join(" AND "), *subs]
- end
-
- private
- def replace_non_alnum_characters!(search_parts)
- search_parts.each do |word|
- word.downcase!
- word.gsub!(/[^[:alnum:]#{FOREIGN_CHARACTERS}]/, '')
- end
- end
-
- def remove_blacklisted_words!(search_parts)
- search_parts.delete_if { |word| word.blank? || BLACKLISTED_WORDS.include?(word.downcase) }
- end
- end
- end
-end
View
15 vendor/plugins/searchlogic/lib/searchlogic/condition/less_than.rb
@@ -1,15 +0,0 @@
-module Searchlogic
- module Condition
- class LessThan < Base
- class << self
- def condition_names_for_column
- super + ["lt", "before"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} < ?", value]
- end
- end
- end
-end
View
15 vendor/plugins/searchlogic/lib/searchlogic/condition/less_than_or_equal_to.rb
@@ -1,15 +0,0 @@
-module Searchlogic
- module Condition
- class LessThanOrEqualTo < Base
- class << self
- def condition_names_for_column
- super + ["lte", "at_most", "most"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} <= ?", value]
- end
- end
- end
-end
View
15 vendor/plugins/searchlogic/lib/searchlogic/condition/like.rb
@@ -1,15 +0,0 @@
-module Searchlogic
- module Condition
- class Like < Base
- class << self
- def condition_names_for_column
- super + ["contains", "has"]
- end
- end
-
- def to_conditions(value)
- ["#{column_sql} #{like_condition_name} ?", "%#{value}%"]
- end
- end
- end
-end
View
21 vendor/plugins/searchlogic/lib/searchlogic/condition/nil.rb
@@ -1,21 +0,0 @@
-module Searchlogic
- module Condition
- class Nil < Base
- self.value_type = :boolean
-