| 38 | | # merge fields from this acts_as_ferret call with predefined fields |
|---|
| 39 | | already_defined_fields = index_definition[:ferret_fields] |
|---|
| 40 | | field_config = ActsAsFerret::build_field_config options[:fields] |
|---|
| 41 | | field_config.update ActsAsFerret::build_field_config( options[:additional_fields] ) |
|---|
| 42 | | field_config.each do |field, config| |
|---|
| 43 | | if already_defined_fields.has_key?(field) |
|---|
| 44 | | logger.info "ignoring redefinition of ferret field #{field}" if shared? |
|---|
| 45 | | else |
|---|
| 46 | | already_defined_fields[field] = config |
|---|
| 47 | | logger.info "adding new field #{field} from class #{clazz.name} to index #{index_name}" |
|---|
| | 36 | if force = options.delete(:force_re_registration) |
|---|
| | 37 | index_definition[:registered_models].delete(clazz) |
|---|
| | 38 | end |
|---|
| | 39 | |
|---|
| | 40 | if index_definition[:registered_models].include?(clazz) |
|---|
| | 41 | logger.info("refusing re-registration of class #{clazz}") |
|---|
| | 42 | else |
|---|
| | 43 | index_definition[:registered_models] << clazz |
|---|
| | 44 | @registered_models_config[clazz] = options |
|---|
| | 45 | |
|---|
| | 46 | # merge fields from this acts_as_ferret call with predefined fields |
|---|
| | 47 | already_defined_fields = index_definition[:ferret_fields] |
|---|
| | 48 | field_config = ActsAsFerret::build_field_config options[:fields] |
|---|
| | 49 | field_config.update ActsAsFerret::build_field_config( options[:additional_fields] ) |
|---|
| | 50 | field_config.each do |field, config| |
|---|
| | 51 | if already_defined_fields.has_key?(field) |
|---|
| | 52 | logger.info "ignoring redefinition of ferret field #{field}" if shared? |
|---|
| | 53 | else |
|---|
| | 54 | already_defined_fields[field] = config |
|---|
| | 55 | logger.info "adding new field #{field} from class #{clazz.name} to index #{index_name}" |
|---|
| | 56 | end |
|---|
| | 57 | end |
|---|
| | 58 | |
|---|
| | 59 | # update default field list to be used by the query parser, unless it |
|---|
| | 60 | # was explicitly given by user. |
|---|
| | 61 | # |
|---|
| | 62 | # It will include all content fields *not* marked as :untokenized. |
|---|
| | 63 | # This fixes the otherwise failing CommentTest#test_stopwords. Basically |
|---|
| | 64 | # this means that by default only tokenized fields (which all fields are |
|---|
| | 65 | # by default) will be searched. If you want to search inside the contents |
|---|
| | 66 | # of an untokenized field, you'll have to explicitly specify it in your |
|---|
| | 67 | # query. |
|---|
| | 68 | unless index_definition[:user_default_field] |
|---|
| | 69 | # grab all tokenized fields |
|---|
| | 70 | ferret_fields = index_definition[:ferret_fields] |
|---|
| | 71 | index_definition[:ferret][:default_field] = ferret_fields.keys.select do |field| |
|---|
| | 72 | ferret_fields[field][:index] != :untokenized |
|---|
| | 73 | end |
|---|
| | 74 | logger.info "default field list for index #{index_name}: #{index_definition[:ferret][:default_field].inspect}" |
|---|
| 50 | | |
|---|
| 51 | | # update default field list to be used by the query parser, unless it |
|---|
| 52 | | # was explicitly given by user. |
|---|
| 53 | | # |
|---|
| 54 | | # It will include all content fields *not* marked as :untokenized. |
|---|
| 55 | | # This fixes the otherwise failing CommentTest#test_stopwords. Basically |
|---|
| 56 | | # this means that by default only tokenized fields (which all fields are |
|---|
| 57 | | # by default) will be searched. If you want to search inside the contents |
|---|
| 58 | | # of an untokenized field, you'll have to explicitly specify it in your |
|---|
| 59 | | # query. |
|---|
| 60 | | unless index_definition[:user_default_field] |
|---|
| 61 | | # grab all tokenized fields |
|---|
| 62 | | ferret_fields = index_definition[:ferret_fields] |
|---|
| 63 | | index_definition[:ferret][:default_field] = ferret_fields.keys.select do |field| |
|---|
| 64 | | ferret_fields[field][:index] != :untokenized |
|---|
| 65 | | end |
|---|
| 66 | | logger.info "default field list for index #{index_name}: #{index_definition[:ferret][:default_field].inspect}" |
|---|
| 67 | | end |
|---|