1

I have a table containing 100m rows and i need to full text search it and provide information about how similar (e.g. with the pg_trgm module) the text's are. Off cause the problem here is that it should be fast.

I tried gist and gin indexes, had a extra column with the tsvector of my field etc.

My idea is to query first using tsvector and after that running the similarity function provided by the pg_trgm module.

My problem is the following. If i use a whole word as my query it will work. But not if i append something.

This makes total sense because the tsvector of "A quick brown fox..." is "'a':1 'brown':3 'fox':4 'quick':2".

I hope i made clear what i would like to achieve.

Example:

works

select to_tsvector('A quick brown fox...') @@ to_tsquery('quick') -- true

does not work

select to_tsvector('A quick brown fox...') @@ to_tsquery('quicks') -- false

Any ideas on how to achieve that using postgresql?

4
  • What version of Postgres is that? Second query gives me true on 9.6.2 EDIT: Oh, checked on 9.6.5 and indeed it works as you described. Commented Oct 12, 2017 at 11:18
  • @ŁukaszKamiński that depends on the dictionary. I get true by default with the "english" dictionary, false if I explicitly use the "simple" dictionary in to_tsquery. This is due to stemming, I think, which would remove the s, but won't just remove any arbitrary characters at the end. Commented Oct 12, 2017 at 11:20
  • @ŁukaszKamiński I got PostgreSQL 9.6.2 Commented Oct 12, 2017 at 11:21
  • @MadScientist indeed. I tried with to_tsquery('english', 'quicks') and get true. Commented Oct 12, 2017 at 11:23

1 Answer 1

1

You need to set the language configuration parameter, like this:

select to_tsvector('english', 'A quick brown fox...') @@ to_tsquery('english', 'quicks')

The capability to recognize lexemes correctly, with plurals and stuff only happens when tsquery and tsvector have the same language configuration.

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.