| CODENOTIFIER | HelpYou are not signed inSign in |
Project: acts_as_ferret
Revision: 355
Author: jk
Date: 11 Aug 2008 05:22:46
Diff at Trac: http://projects.jkraemer.net/acts_as_ferret/changeset/355
Changes:fix model array handling for find_ids and totalhits methods
Files:| ... | ...@@ -269,25 +269,27 @@ | |
| 269 | 269 | ferret_indexes[name] |
| 270 | 270 | end |
| 271 | 271 | |
| 272 | # count hits for a query with multiple models | |
| 273 | def self.total_hits(query, models, options = {}) | |
| 274 | find_index(models).total_hits query, options.merge( :models => models ) | |
| 272 | # count hits for a query | |
| 273 | def self.total_hits(query, models_or_index_name, options = {}) | |
| 274 | options = add_models_to_options_if_necessary options, models_or_index_name | |
| 275 | find_index(models).total_hits query, options | |
| 275 | 276 | end |
| 276 | 277 | |
| 277 | # find ids of records with multiple models | |
| 278 | # TODO pagination logic? | |
| 279 | def self.find_ids(query, models, options = {}, &block) | |
| 280 | find_index(models).find_ids query, options.merge( :models => models ), &block | |
| 278 | # find ids of records | |
| 279 | def self.find_ids(query, models_or_index_name, options = {}, &block) | |
| 280 | options = add_models_to_options_if_necessary options, models_or_index_name | |
| 281 | find_index(models).find_ids query, options, &block | |
| 281 | 282 | end |
| 282 | ||
| 283 | ||
| 284 | # returns an index instance suitable for searching/updating the named index. Will | |
| 285 | # return a read only MultiIndex when multiple model classes are given that do not | |
| 286 | # share the same physical index. | |
| 283 | 287 | def self.find_index(models_or_index_name) |
| 284 | 288 | case models_or_index_name |
| 285 | 289 | when Symbol |
| 286 | 290 | get_index models_or_index_name |
| 287 | 291 | when String |
| 288 | 292 | get_index models_or_index_name.to_sym |
| 289 | #when Array | |
| 290 | # get_index_for models_or_index_name | |
| 291 | 293 | else |
| 292 | 294 | get_index_for models_or_index_name |
| 293 | 295 | end |
| ... | ...@@ -305,7 +307,7 @@ | |
| 305 | 307 | nil |
| 306 | 308 | end |
| 307 | 309 | index = find_index(models_or_index_name) |
| 308 | multi = (MultiIndex === index or index.shared?) | |
| 310 | multi = (MultiIndexBase === index or index.shared?) | |
| 309 | 311 | unless options[:per_page] |
| 310 | 312 | options[:limit] ||= ar_options.delete :limit |
| 311 | 313 | options[:offset] ||= ar_options.delete :offset |
| ... | ...@@ -556,6 +558,11 @@ | |
| 556 | 558 | |
| 557 | 559 | protected |
| 558 | 560 | |
| 561 | def self.add_models_to_options_if_necessary(options, models_or_index_name) | |
| 562 | return options if String === models_or_index_name or Symbol === models_or_index_name | |
| 563 | options.merge(:models => models) | |
| 564 | end | |
| 565 | ||
| 559 | 566 | def self.field_config_for(fieldname, options = {}) |
| 560 | 567 | config = DEFAULT_FIELD_OPTIONS.merge options |
| 561 | 568 | config[:via] ||= fieldname |
| ... | ...@@ -103,10 +103,6 @@ | |
| 103 | 103 | add_fields aaf_configuration[:fields] |
| 104 | 104 | add_fields aaf_configuration[:additional_fields] |
| 105 | 105 | |
| 106 | # not good at class level, index might get initialized too early | |
| 107 | #if options[:remote] | |
| 108 | # aaf_index.ensure_index_exists | |
| 109 | #end | |
| 110 | 106 | end |
| 111 | 107 | |
| 112 | 108 | |
| ... | ...@@ -135,10 +131,6 @@ | |
| 135 | 131 | end |
| 136 | 132 | |
| 137 | 133 | def add_fields(field_config) |
| 138 | # TODO | |
| 139 | #field_config.each do |*args| | |
| 140 | # define_to_field_method *args | |
| 141 | #end | |
| 142 | 134 | if field_config.is_a? Hash |
| 143 | 135 | field_config.each_pair do |field, options| |
| 144 | 136 | define_to_field_method field, options |