title: Sphinx indexer custom query for sql_attr_multi
body: <p>I managed to have a query for getting all the friends and friends of friends of a particular user. I have a users table and a friendships join table. For simplicity, lets just say that the users table only has a primary key. The friendships table has the user_id and friend_id columns. The query is as follows:</p>
  
  <pre><code>"SELECT DISTINCT friends.user_id, friends.friend_id, users.*
  
    FROM FRIENDSHIPS friends, USERS 
  
    WHERE USERS.id = friends.friend_id AND friends.user_id = #{u.id}
  
    UNION
  
    SELECT DISTINCT fof.user_id, fof.friend_id, users.*
  
    FROM FRIENDSHIPS friends, FRIENDSHIPS fof, USERS
  
    WHERE USERS.id = fof.friend_id AND friends.friend_id = fof.user_id AND friends.user_id = #{u.id}"
  </code></pre>
  
  <p>u.id is the id of the user whom I wish to get all the friends and friends of friends.</p>
  
  <p>This query works very well however I would like to convert this to a query usable by sphinx's sql_attr_multi. I tried directly placing it like so:</p>
  
  <pre><code>sql_attr_multi = uint fwfof from query; \
    SELECT DISTINCT `friends`.`user_id`, `friends`.`friend_id`, `users`.`id` \
    FROM `friendships` friends, `users` \
    WHERE `users`.`id` = `friends`.`friend_id` AND `friends`.`user_id` = $id \
    UNION \
    SELECT DISTINCT `fof`.`user_id`, `fof`.`friend_id`, `users`.`id` \
    FROM `friendships` `friends`, `friendships` `fof`, `users` \
    WHERE `users`.`id` = `fof`.`friend_id` AND `friends`.`friend_id` = `fof`.`user_id` AND `friends`.`user_id` = $id
  </code></pre>
  
  <p>but that obviously failed.</p>
  
  <p>How do I make this query usable by sphinx's indexer?</p>
  
  <p>Thanks in advance for anything that will point me in the right direction.</p>