问题
I'm using full text search supported by postgres, I installed acts_as_tsearch
plugin and it works successfully, but when I tried it later I found an error
runtimeError: ERROR C42883 Mfunction ts_rank_cd(text, tsquery) does not exist HNo function matches the given name and argument types. You might need to add explicit type
回答1:
You need to cast your first parameter into a tsvector.
So let's assume you're searching against a column named foo.text
. You will want to change from this:
SELECT ts_rank_cd(foo.text, plainto_tsquery('my search terms')) FROM foo;
to this:
SELECT ts_rank_cd(to_tsvector(foo.text), plainto_tsquery('my search terms')) FROM foo;
or something similar.
If you're using the @@
operator elsewhere, you can generally re-use the expressions that operator is operating on.
You can find more documentation on to_tsvector
at http://www.postgresql.org/docs/current/static/textsearch-controls.html#TEXTSEARCH-PARSING-DOCUMENTS
回答2:
EDIT
ts_rank_cd(text, tsquery) does not exist
This means there is no function with this name that accepts text and a tsquery parameter as input. And that's correct, PostgreSQL doens't have a function using these parameters.
From the manual:
ts_rank_cd([ weights float4[], ] vector tsvector, query tsquery [, normalization integer ])
Change your input for the function ts_rank_cd() and you will be fine.
来源:https://stackoverflow.com/questions/3501831/function-ts-rank-cdtext-tsquery-does-not-exist