3

I have a table with four language translated columns. E. g., if there is, for example, description data, there are four columns in database: description_en, description_de, description_it and description_fr.

I built an index and tsv::tsvector column gathering all of those columns' data into one tsvector-column.

Querying that table with tsv @@ to_tsquery(#{ search_query }) is nice, but I would like to match rows with search_query being misspelled. In other words, to perform fuzzy search. Yet, I wish it to be as fast as possible as my table is really huge...

So I am wondering, is it ever possible in Postgres to match my tsv column over metaphone(#{ search_query }, 2) somehow?

So, for example, strings Herrenarmbanduhr and heren got matched.

UPD: I have some... medium amount of translated columns, so matching those with metaphone(column_a, 2) = metaphone(query, 2) OR metaphone(column_b, 2) = metaphone(query, 2)... is a pain for me...

shybovycha
  • 11,556
  • 6
  • 52
  • 82

1 Answers1

1

This is not supported out of the box to my knowledge.

It ought to be possible to write a routine (perhaps a C language function?) to turn a tsvector to something like an array of text values and then use other search functionality to do a phonetic search on those. Since the initial conversion and the phonetic transformation would be immutable you could index the output.

But this is not supported out of the box and would be at least a bit of work.

Chris Travers
  • 25,424
  • 6
  • 65
  • 182