Class | ThinkingSphinx::Attribute |
In: |
lib/thinking_sphinx/attribute.rb
|
Parent: | ThinkingSphinx::Property |
Attributes - eternally useful when it comes to filtering, sorting or grouping. This class isn‘t really useful to you unless you‘re hacking around with the internals of Thinking Sphinx - but hey, don‘t let that stop you.
One key thing to remember - if you‘re using the attribute manually to generate SQL statements, you‘ll need to set the base model, and all the associations. Which can get messy. Use Index.link!, it really helps.
query_source | [RW] |
To create a new attribute, you‘ll need to pass in either a single Column or an array of them, and some (optional) options.
Valid options are:
Alias is only required in three circumstances: when there‘s another attribute or field with the same name, when the column name is ‘id’, or when there‘s more than one column.
Type is not required, unless you want to force a column to be a certain type (but keep in mind the value will not be CASTed in the SQL statements). The only time you really need to use this is when the type can‘t be figured out by the column - ie: when not actually using a database column as your source.
Source is only used for multi-value attributes (MVA). By default this will use a left-join and a group_concat to obtain the values. For better performance during indexing it can be beneficial to let Sphinx use a separate query to retrieve all document,value-pairs. Either :query or :ranged_query will enable this feature, where :ranged_query will cause the query to be executed incremental.
Example usage:
Attribute.new( Column.new(:created_at) ) Attribute.new( Column.new(:posts, :id), :as => :post_ids ) Attribute.new( Column.new(:posts, :id), :as => :post_ids, :source => :ranged_query ) Attribute.new( [Column.new(:pages, :id), Column.new(:articles, :id)], :as => :content_ids ) Attribute.new( Column.new("NOW()"), :as => :indexed_at, :type => :datetime )
If you‘re creating attributes for latitude and longitude, don‘t forget that Sphinx expects these values to be in radians.
Returns the configuration value that should be used for the attribute. Special case is the multi-valued attribute that needs some extra configuration.
Get the part of the SELECT clause related to this attribute. Don‘t forget to set your model and associations first though.
This will concatenate strings and arrays of integers, and convert datetimes to timestamps, as needed.
Returns the type of the column. If that‘s not already set, it returns :multi if there‘s the possibility of more than one value, :string if there‘s more than one association, otherwise it figures out what the actual column‘s datatype is and returns that.