iamsk
iamsk

Reputation: 356

postgres fulltext index for email

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.

Upvotes: 3

Views: 2098

Answers (1)

Daniel Vérité
Daniel Vérité

Reputation: 61506

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.

Upvotes: 3

Related Questions