0

I thought that

Match('^Word$')

Would only find records that are exactly 'Word'

However although this does work for single words it does not for mutliple:

Match ('^Final Word$')

Finds 'Final Word' and 'Final and Last Word'.

as does

Match ('^"Final Word"$')

How do I tell Sphinx to only find an exact match?


Update: After some testing the best I can do is weighting/ranker and w/o ""

MATCH('^Final Word$') order by weight() desc limit 1 desc  OPTION ranker=PROXIMITY_BM25

So I forced an exact match with ranking and limit, still would be nice to know how to actually say 'only return exact matches'.

One issue with above is if I do not have 'Final Word' in the table it will find all others e.g. 'Final and Last Word' which is behavior I do not want.

user3649739
  • 1,829
  • 2
  • 18
  • 28

2 Answers2

0

You just got your operators in wrong order :)

Match('"^Final Word$ "')

(having a space after $ helps with some mysterious sphinx bug!)

barryhunter
  • 20,886
  • 3
  • 30
  • 43
  • That way returns zero results regardless of matches for some reason. – user3649739 Apr 23 '17 at 14:41
  • What version of sphinx? Try with a space after the $, there was a bug in some versions, that would mysterilly not work! I tried to put that in my reply above, but did it worng! – barryhunter Apr 23 '17 at 18:46
  • @BarrHunter I don't suppose you want to give this question a whirl?: http://stackoverflow.com/questions/43381060/indexing-euro-%E2%82%AC-and-lb-%C2%A3-in-sphinx – user3649739 Apr 23 '17 at 18:56
  • My version is `Sphinx 2.2.11-id64-release (95ae9a6)` The `"^Final Word$"` definitely fails as does `"^Final Word$ "` – user3649739 Apr 23 '17 at 22:39
  • I probably know less about charsets than you. – barryhunter Apr 24 '17 at 10:20
  • This turns out to be unsolvable to date and is in fact breaking my entire search. `"^Final Word$"` still finds nothing and `^Final Word$` find results like `Final Other Words Word`. If Sphinx can't find an exact match in my case all the other work is for naught. – user3649739 May 27 '17 at 00:23
0

So the issue turned out to be that in my efforts to make this work one step had been to specify the ranker

Option Ranker=PROXIMITY_BM25

which had worked for me up to then. What actually works is

Match('^Final Word$')

and then not specifying ranker or specifying extended if the ranker in config is defined otherwise (it is extended by default).

user3649739
  • 1,829
  • 2
  • 18
  • 28