Xeoncross
Xeoncross

Reputation: 57184

Use different table column for sphinx search weight sorting

Rather than the default sorting in sphinx, I would like to sort/weight results based on a field in another table. My schema looks like this:

node {
  id
  weight
}

node_text {
  id
  node_id
  text
}

(Note: There is only one node_text for each node)

I want to index node_text, but be able to return sphinx results ordered by node.weight. I am assuming I need something like this:

sql_query = SELECT node_id, text from node_text

sql_joined_field = weight from query; SELECT id, weight FROM node ORDER BY id ASC

Is this the correct way to search for matches ORDER BY node.weight DESC? I would like to be able to run a query like the following:

mysql> SELECT * FROM nodetest1 WHERE MATCH('foobar') ORDER BY weight DESC; SHOW META;

Upvotes: 0

Views: 247

Answers (1)

barryhunter
barryhunter

Reputation: 21091

sql_joined_field, makes a field, you need weight to be stored in an attribute. Easiest would be a simple join...

sql_query = select node_id, text, weight from node_text inner join node using (node_id=node.id)
sql_uint_attr = weight

That should then work for you SphinxQL query :)

Upvotes: 1

Related Questions