0

I have a large table with the columns name, phone number, and type of relationship to me (friend, family, acquaintance, etc.). When I search a name in Sphinx I want the results with the field value "family" to be weighted higher than "acquaintance." How do I manually set the weight of a certain row so that it is weighted higher?

user3038754
  • 185
  • 4
  • 11

1 Answers1

0

Many options...

A) you could store the 'type' in an attribute - attributes are stored in teh index (unlike fields) and can be used to sort the results.

How exactly you do it thou is largely a matter of personal preference.

For example:

sql_query = SELECT id,name,phone,type,(type=family) as boost from table
sql_attr_bool = boost

Then queries can be sorted by boost attribute. ... ORDER BY boost DESC, WEIGHT() DESC

You could also just store the type as a plain numeric integer, with a value for each type, setup in such a way can just naturally sort by that column.


or B) you can actually just leave the type as a field, and boost the results,

for example extended query

john | (john @type family)

Need john on both sides of the OR, so that will always have rows that include john. But because its on both sides, results that also match family, will match more keywords, and rank higher.

Can choose how much it affects the results, using field-weights option.

(latest versions of sphinx has MAYBE operator to do this even easier)

barryhunter
  • 20,886
  • 3
  • 30
  • 43