sphinxsphinxql

Sphinx(Search) - documents which matches keyword twice (thrice, etc.)


Is there a way to only output documents which contains n matches of a search term in it?

F.e. I want to output all documents containing the search term "Pablo Picasso" | "Picasso Pablo" at least two (three, n) times. How would such a query look like?

My current query is: SELECT * FROM myIndex WHERE MATCH('"Pablo Picasso" | "Picasso Pablo"');


Solution

  • You could do it with filtering by weight (ie results with it multiple time wil rank higher)

    But a useful trick is the Strict order operator...

    MATCH('Pablo << Pablo')
    

    would require the word twice (ie one before the other!)


    You can also use the primoxity operator to simplify your original query, it just wants the words near each other, which is more conise than two phrase operators

    MATCH('"Pablo Picasso"~1')
    

    ... ie within 1 word of each other - ie adjent.


    Combine the two..

    MATCH('"Pablo Picasso"~1 << "Pablo Picasso"~1')
    

    and for theree occurances

    MATCH('"Pablo Picasso"~1 << "Pablo Picasso"~1 << "Pablo Picasso"~1')