Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

postgres fulltext index for email

Tags:

sql

postgresql

I want get [email protected] by searching lei4 or gmail.com.

ts_debug

The first one only have token: email.

What I want is like the second one

Can we parse the email to email, asciiword and host token? any ideas will help.

I already read the tsearch2 guide, reference, etc. can't find the solution.

like image 398
iamsk Avatar asked Aug 24 '26 15:08

iamsk


1 Answers

A simple solution would be to transform email addresses into local-part at domain-part before feeding them to the TS parser.

Since at is a stop word in english, it will be ignored.

=> select to_tsvector('english','lei4 at gmail.com');
      to_tsvector       
------------------------
 'gmail.com':3 'lei4':1

So both lei4 and gmail.com are going to be found in this tsvector.

As a side note, [email protected] is a valid email address and the TS parser is wrong in tokenizing it into four parts.

like image 128
Daniel Vérité Avatar answered Aug 26 '26 10:08

Daniel Vérité



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!