snippetsqlMinor
How can I query for terms like "@foo" with Postgres full text search?
Viewed 0 times
canfullfoopostgreswithsearchquerytextlikefor
Problem
I would like to be able to query for documents containing
Is there a way to force Postgres to treat the
@foo without matching the naked word foo. I'm using the simple dictionary but I notice @ characters are stripped:SELECT to_tsquery('simple', '@foo'); -- produces 'foo'Is there a way to force Postgres to treat the
@ as significant?Solution
The problem is the default text parser, in that it splits out the '@' symbol
You can see it here:
lexize is fine and keeps the
You'd need to write your own parser or change the source, which isn't fun if you don't know C!
One work-around would be to change
You can see it here:
select
ts_lexize('simple', '@foo'), -- {@foo}
ts_parse('default', '@foo'); -- { (12,@), (1,foo) }lexize is fine and keeps the
@, but the parser splits it outYou'd need to write your own parser or change the source, which isn't fun if you don't know C!
One work-around would be to change
@foo to something like ATSYMBOLfoo using some wrapper function for to_tsvector and plainto_tsqueryCode Snippets
select
ts_lexize('simple', '@foo'), -- {@foo}
ts_parse('default', '@foo'); -- { (12,@), (1,foo) }Context
StackExchange Database Administrators Q#180303, answer score: 3
Revisions (0)
No revisions yet.