Обсуждение: Postgres function for full text search

Поиск
Список
Период
Сортировка

Postgres function for full text search

От
-
Дата:
Hello everyone.<br />My question if any known one postgres function, for full text search that separates words with "|
"?<br/>As plainto_tsquery separating words with "& ".<br /><br />For example text "word1 word2 word3 word4"<br />
andconversion rates for full text search postgres "word1 | word2 | word3 | word4"<br /><br />Or i must create an own
functioneg. on the java for normalize text for search.<br />I guess there would not need to remove not allowed words
fromtext to prevent sql injection...?<br /><br />Thanks and regards<br /> 

Re: Postgres function for full text search

От
Ivan Sergio Borgonovo
Дата:
On Mon, 24 Jan 2011 10:38:02 +0100
- <grandebuzon@gmail.com> wrote:

> Hello everyone.
> My question if any known one postgres function, for full text
> search that separates words with "| "?
> As plainto_tsquery separating words with "& ".
> 
> For example text "word1 word2 word3 word4"
> and conversion rates for full text search postgres "word1 | word2
> | word3 | word4"

I wrote a C extension that could help...

Currently there are
CREATE OR REPLACE FUNCTION tsvector_to_table(
IN tsv tsvector,
OUT lexeme text,
OUT weight smallint[],
OUT pos int[])

CREATE OR REPLACE FUNCTION tsvector_to_tsquery(
IN tsv tsvector,
op IN char(1),
weights IN varchar(4),
maxpos IN smallint )
RETURNS tsquery

op is | or &
It will ignore elements in the tsvector whose position is >maxpos.
It will ignore elements whose weight is not in weights

So it could turn
gino:1,3,5A pino:2B into
gino:A | pino:B

The code has been working in production by several months but:
- it is for 8.3 (there are some notes to port it to >8.4, namely supporting prefixes)
- I wrote it for my environment so the "build" script are simple but you'll have to adjust them to your environment.

The code could be released in GPL or FreeBSD license.
I'd be happy if someone could guide me in the process of
successfully donating this code to the community.

-- 
Ivan Sergio Borgonovo
http://www.webthatworks.it