Search code examples
sphinx

Using NOT inside queries with order operators in Sphinx


I'm trying to query TermA and TermB in specific order

TermA << TermB

or sentence

TermA SENTENCE TermB

But only want them when specific words do NOT occur between them

TermA -(NOT1 | NOT2 | NOT3) << TermB

But I get the error "NOT cannot be used as before operand"

Essentially trying to find

TermA (-A | -B | -C) TermB

either inside a sentence or a given proximity e.g.

 (TermA (-A | -B | -C) TermB)~10

or

TermA SENTENCE (-A | -B | -C) SENTENCE TermB

But any combination I use fails. Caveat is I am just starting with Sphinx


Solution

  • The closest might be

    (TermA -(NOT1 | NOT2 | NOT3)) << TermB
    

    which I think should run.

    But might exclude some matches. eg if the document simpley contains NOT1 anywhere the document wont match.

    I have suggested a negative assertion operator, but nothing has come of it http://sphinxsearch.com/bugs/view.php?id=1259


    also linked from that bug report, is the original thread on the sphinx forum http://sphinxsearch.com/forum/view.html?id=9869 ... I do discuss a workaround I found for that example. I think the same trick might work for you, more thought needed...