D
D
den2a2017-12-14 14:09:49
Sphinx
den2a, 2017-12-14 14:09:49

How to set Sphinx relevance to the beginning of the line?

I make a request and get the result.
Query: brush

  • Second glue Super Moment Pro plus with a brush , 5g
  • Flux for soldering soldering acid with a brush 25ml REXANT
  • Silicone brush 18.5 cm Function Form Fiskars
  • Dough brush 22.5 cm KL40A09-08
  • Brush brush 12mm, c/x 6mm, canil . wire 0,3mm KERN
  • Brush brush 25mm, c/x 6mm, canil . wire 0,3mm KERN
  • Baking brush 158x40mm

How to sort like this:
  • Silicone brush 18.5 cm Function Form Fiskars
  • Dough brush 22.5 cm KL40A09-08
  • Baking brush 158x40mm
  • Brush brush 12mm, c/x 6mm, canil . wire 0,3mm KERN
  • Brush brush 25mm, c/x 6mm, canil . wire 0,3mm KERN
  • Flux for soldering soldering acid with a brush 25ml REXANT
  • Second glue Super Moment Pro plus with a brush , 5g

Those. the closer the keyword is to the beginning of the line, the higher the weight.
Thanks in advance!

Answer the question

In order to leave comments, you need to log in

5 answer(s)
D
den2a, 2017-12-18
@den2a

Key parameter min_hit_pos
More details here
As an option:

$query = 'кисточ';

  try {
    $sp = new PDO('mysql:host=127.0.0.1;port=9306', '', '');
    $list = $sp->query("SELECT * FROM test1 WHERE MATCH('$query') OPTION ranker = expr('sum(4*lcs+100/(min_hit_pos)+bm25)')");
    
    while ( $row = $list->fetch(PDO::FETCH_ASSOC) ) { //Преобразуем результат в ассоциативный массив
      echo $row['id'] . ' - '; //id товара в mysql
      echo $row['weight'] . ' - '; //Релевантный вес
      echo $row['name'] . '<br/>'; //Название товара
    };
    
  } catch( PDOException $e) {
    echo "You have an error: ".$e->getMessage()."<br>";
    echo "On line: ".$e->getLine();
  }

D
dllweb, 2017-12-14
@dllweb

Go in the direction of relevance and query popularity weights, and then sort by this index, how could it be otherwise?

B
Boris Korobkov, 2017-12-14
@BorisKorobkov

In select, add a separate "Short Title" field, which is built on the fly as the first 2 words of the line (if the second word is "for", then without it). Or not 2 words, but the whole line before the punctuation mark, "for", "with".
And assign a high weight to this field.

P
Puma Thailand, 2017-12-14
@opium

Sort separately in the app

M
Mikhail Borisov, 2020-09-10
@valickSerjGe

In the select, add a separate "Short Title" field

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question