Use field twice in sphinx-query with different user_weights

181 Views Asked by At

I've got a working index and everything is fine, but there's a little thing that is bothering me. There is one query in which I'm searching the same field twice with different strings and I'd like to assign different user_weights to those.

I've got this working by altering the index, selecting the field twice with different names. But this feels a little bit wrong to me.

Is it possible to use the same Field twice with different user weights?

I read about keyword boosting, but as my queries are mostly a bit more complex than a single keyword this is going to be a little bit messy.

Example query (I cleaned this up a little bit, the lists of searchterms is generated):

SELECT titel, age_firstdate, age_priodatum, uniqueserial(partner) as sortid,
        weight() as w, if (w > 200000, IF(w > 500000, 2, 1) ,0)  as intitel, IF (w>5000, 1, 0) as ingroup,
        sort_w + sort_intitel as score, 0 as geodist
    FROM anzeigen
    WHERE MATCH('( 
    (@titel_dup wachfrau) |
    (@titel_mf (wachmann|wachfrau|wachleute)) |
    (@titel (("Fachkraft Schutz Sicherheit"|[...]|"Wachleute"))) |
    (@titel_low (("Security Detektiv"|[...]|"450 Security"))))
') AND  geodist <= 30
    ORDER BY geodist ASC, intitel DESC, ingroup DESC, score DESC
    LIMIT 10000
    OPTION  max_matches=100000, field_weights = (titel_dup=500001, titel_mf=200001, titel=5001, titel_low = 100, beschreibung=5),
ranker=expr('sum(word_count*user_weight*lcs)')

index-definition (cleaned up too):

sql_query = SELECT SQL_NO_CACHE \
        s.id, s.titel, s.titel as titel_dup, s.titel as titel_mf, s.titel as titel_low,[...] \
 FROM _sphinxSource s

sql_field_string         = titel
sql_field_string         = titel_dup
sql_field_string         = titel_mf
sql_field_string         = titel_low

I also tried the following in Sphinxql:

SELECT [...] titel as title_dup, title as title_low 
[...] OPTIONS field_weights = (titel_dup=500001, titel_mf=200001)
[...]

Which would be a nice solution but doesn't work.

0

There are 0 best solutions below