Pat, Sorry I was confused - its not returning an empty array - that was from before. Its returning all the records, even if a user has no subscriptions, its still returns all the matches for the descriptions regardless of the user_id.
Sorry for the confusion - I've tried so many combinations :) B On Feb 12, 1:39 am, brian <[email protected]> wrote: > def self.filter_streams(user_id, filter_text=nil, page=1, > per_page=UPLOADS_RESULTS_PER_PAGE) > > conditions = { > :user_id => user_id, > :creator_id => "creator_id <> #{user_id}" > } > > date = Chronic.parse(filter_text) > unless date.nil? > conditions[:created_at] = > date.beginning_of_day.to_i..date.end_of_day.to_i > filter_text = nil > end > > Upload.search(filter_text, :conditions => conditions, > :page => page, :per_page => per_page, :order => > [:created_at, :id]) > end > > I've tried different combinations of have user_id or the date or both, > but I get nothing back unless I use only the filter_text for the > description. > > Chronic is a date parser that returns nil if it doesn't recognize the > date. So it will search or for date or for the text if it doesn't. > > B > > On Feb 12, 12:26 am, Pat Allan <[email protected]> wrote: > > > How are you querying against user_id and/or creator_id? > > > Cheers > > > -- > > Pat > > > On 12/02/2009, at 4:25 PM, brian wrote: > > > > Hi Pat, > > > > Thanks for looking at this. Its my first time using sphinx, but I've > > > found it pretty good so far. I'm using other indexes in my app > > > without any trouble. > > > > Its returning the correct records. It works with description, but > > > when I add the :creator_id, I get an empty array back. I want to > > > search within uploads for entities that I'm subscribed to. > > > > Thanks, > > > Brian > > > > On Feb 11, 9:01 pm, Pat Allan <[email protected]> wrote: > > >> Hi Brian > > > >> Do you get the expected data in the user_id column if you run that > > >> SQL > > >> query (stripping out the id filtering in the WHERE clause, of > > >> course)? > > > >> -- > > >> Pat > > > >> On 12/02/2009, at 1:31 AM, brian wrote: > > > >>> Here is the sql that I have: > > > >>> SELECT `uploads`.`id` * 3 + 1 AS `id` , CAST(`uploads`.`description` > > >>> AS CHAR) AS `description`, UNIX_TIMESTAMP(`uploads`.`created_at`) AS > > >>> `created_at`, `uploads`.`creator_id` AS `creator_id`, GROUP_CONCAT > > >>> (`subscriptions`.`user_id` SEPARATOR ',') AS `user_id`, > > >>> `uploads`.`id` > > >>> AS `sphinx_internal_id`, 269607721 AS `class_crc`, '269607721' AS > > >>> `subclass_crcs`, 0 AS `sphinx_deleted` > > > >>> FROM uploads > > >>> LEFT OUTER JOIN `entities` ON `entities`.id = `uploads`.entity_id > > >>> LEFT OUTER JOIN `subscriptions` ON subscriptions.entity_id = > > >>> entities.id > > > >>> WHERE `uploads`.`id` >= $start AND `uploads`.`id` <= $end AND > > >>> `uploads`.`delta` = 0 GROUP BY `uploads`.`id` > > > >>> ORDER BY NULL > > > >>> On Feb 10, 11:45 pm, Pat Allan <[email protected]> wrote: > > >>>> Hi Brian > > > >>>> From an initial look, it seems like you're doing the right thing - > > >>>> although entity.subscriptions(:user_id) could be done as > > >>>> entity.subscriptions.user_id. > > > >>>> What's the sql_query in your development.sphinx.conf file for the > > >>>> Upload index? > > > >>>> -- > > >>>> Pat > > > >>>> On 11/02/2009, at 5:27 AM, brian wrote: > > > >>>>> I'm trying to get associations working, but can't seem to get it > > >>>>> right. I have users, who can subscribe to entities. Entities > > >>>>> have > > >>>>> uploads and uploads have descriptions. I want to search > > >>>>> upload.description through all of a user's subscription. > > > >>>>> Here are my models: > > > >>>>> class User < ActiveRecord::Base > > >>>>> has_many :subscriptions > > >>>>> has_many :entity_subscriptions, :through > > >>>>> => :subscriptions, :source > > >>>>> => 'entity' > > >>>>> has_many :entities, :foreign_key => 'owner_id' > > >>>>> ... > > >>>>> end > > > >>>>> class Entity < ActiveRecord::Base > > >>>>> has_many :uploads > > >>>>> has_many :subscriptions > > >>>>> has_many :subscribers, :through => :subscriptions, :source => > > >>>>> 'user' > > >>>>> ... > > >>>>> end > > > >>>>> class Subscription < ActiveRecord::Base > > >>>>> belongs_to :entity > > >>>>> belongs_to :user > > >>>>> end > > > >>>>> class Upload < ActiveRecord::Base > > >>>>> belongs_to :entity > > > >>>>> define_index do > > >>>>> indexes description > > >>>>> has :created_at > > >>>>> has :creator_id > > >>>>> has entity.subscriptions(:user_id), :as => :user_id > > >>>>> set_property :delta => true > > >>>>> end > > >>>>> ... > > >>>>> end > > > >>>>> If I add in user id, i don't get subscriptions for the user that I > > >>>>> want. I think I've just set it up wrong, any help is greatly > > >>>>> apprieciated. > > > >>>>> Thanks, > > >>>>> Brian > > --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Thinking Sphinx" group. To post to this group, send email to [email protected] To unsubscribe from this group, send email to [email protected] For more options, visit this group at http://groups.google.com/group/thinking-sphinx?hl=en -~----------~----~----~----~------~----~------~--~---
