Hi Katherine A few that are worth noting, and should help resolve the issue:
* You don't need to use the arguments approach when chaining associations/paths (e.g. tag(:name) should become tag.name) - the old syntax was to workaround conflicts with Rake and Ruby 1.8 - and TS 3.x requires Ruby 1.9 or newer, so we can stick to the standard method chaining instead. * Associations within an index should be referred to with the names they're defined with in the corresponding model. Thus, tag and response should be tags and responses: indexes tags.name, as: :tags indexes responses.body, as: :response_bodies * It may be worth going through full association paths, instead of using has_many :through shortcuts. Hence, the tag name field becomes: indexes taggings.tag.name, as: :tags Note that 'tag' is now back to the singular, because from the context of a Tagging, that's what the association name is. Those changes should hopefully have indexing working. One other thing to mention, though, is that because both fields are concatenation of many values, sorting isn't really useful here, hence I've not kept the sortable option for either field definition. Hope this helps! -- Pat On 7 Aug 2014, at 11:29 pm, Katherine Abu Hadal <[email protected]> wrote: > I am trying to index the following items for story, however when I add > tag(:name) and response.body it gives me a syntax error (see below). Without > the associations, the indexes on title and body work fine. But when I add > associations it crashes. Any ideas? Thank you. > > story_index.rb > > ThinkingSphinx::Index.define :story, with: :active_record do > indexes title, sortable: true > indexes body > > indexes tag(:name), as: :tag, sortable: true > indexes response.body, as: :response_body, sortable: true > > has created_at, updated_at > end > > story.rb > > class Story < ActiveRecord::Base > include TagListable > > belongs_to :user > has_many :likes, dependent: :destroy > has_many :responses, dependent: :destroy > has_many :taggings, as: :taggable > has_many :tags, through: :taggings > > validates :body, presence: true > validates :title, presence: true > validates :user, presence: true > > def self.recent > order(created_at: :desc).limit(9) > end > end > > > error > > Generating configuration to > /Users/metis/i_am_mixed/config/development.sphinx.conf > Sphinx 2.1.8-release (rel21-r4675) > Copyright (c) 2001-2014, Andrew Aksyonoff > Copyright (c) 2008-2014, Sphinx Technologies Inc (http://sphinxsearch.com) > > using config file '/Users/metis/i_am_mixed/config/development.sphinx.conf'... > indexing index 'response_core'... > collected 1 docs, 0.0 MB > sorted 0.0 Mhits, 100.0% done > total 1 docs, 10 bytes > total 0.016 sec, 593 bytes/sec, 59.35 docs/sec > indexing index 'story_core'... > ERROR: index 'story_core': sql_range_query: ERROR: syntax error at or near > "AS" > LINE 1: ...es."title" AS "title", stories."body" AS "body", AS "tag", ... > ^ > (DSN=pgsql://metis:***@localhost:5432/i_am_mixed_development). > total 0 docs, 0 bytes > total 0.005 sec, 0 bytes/sec, 0.00 docs/sec > indexing index 'tag_core'... > collected 12 docs, 0.0 MB > sorted 0.0 Mhits, 100.0% done > total 12 docs, 40 bytes > total 0.011 sec, 3353 bytes/sec, 1005.95 docs/sec > skipping non-plain index 'response'... > skipping non-plain index 'story'... > skipping non-plain index 'tag'... > total 6 reads, 0.000 sec, 0.0 kb/call avg, 0.0 msec/call avg > total 20 writes, 0.000 sec, 0.1 kb/call avg, 0.0 msec/call avg > > > > My schema > > > create_table "responses", force: true do |t| > t.integer "user_id", null: false > t.integer "story_id", null: false > t.text "body", null: false > t.datetime "created_at", null: false > t.datetime "updated_at", null: false > end > > add_index "responses", ["story_id"], name: "index_responses_on_story_id", > using: :btree > add_index "responses", ["user_id"], name: "index_responses_on_user_id", > using: :btree > > create_table "stories", force: true do |t| > t.string "image", default: "", null: false > t.integer "user_id", null: false > t.string "title", null: false > t.text "body", null: false > t.datetime "created_at", null: false > t.datetime "updated_at", null: false > end > > add_index "stories", ["user_id"], name: "index_stories_on_user_id", using: > :btree > > create_table "taggings", force: true do |t| > t.integer "taggable_id", null: false > t.string "taggable_type", null: false > t.integer "tag_id", null: false > end > > add_index "taggings", ["taggable_id", "tag_id"], name: > "index_taggings_on_taggable_id_and_tag_id", unique: true, using: :btree > > create_table "tags", force: true do |t| > t.string "name", null: false > t.datetime "created_at", null: false > t.datetime "updated_at", null: false > end > > add_index "tags", ["name"], name: "index_tags_on_name", unique: true, > using: :btree > > > -- > You received this message because you are subscribed to the Google Groups > "Thinking Sphinx" group. > To unsubscribe from this group and stop receiving emails from it, send an > email to [email protected]. > To post to this group, send email to [email protected]. > Visit this group at http://groups.google.com/group/thinking-sphinx. > For more options, visit https://groups.google.com/d/optout. -- You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To unsubscribe from this group and stop receiving emails from it, send an email to [email protected]. To post to this group, send email to [email protected]. Visit this group at http://groups.google.com/group/thinking-sphinx. For more options, visit https://groups.google.com/d/optout.
