TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Similarity in Postgres and Rails Using Trigrams

66 pointsby moritzplassnigover 5 years ago

7 comments

oliverx0over 5 years ago
Out of curiosity, how does this compare to using tsvector?<p><a href="https:&#x2F;&#x2F;coderwall.com&#x2F;p&#x2F;vngr0a&#x2F;simple-full-text-search-using-postgres-on-rails" rel="nofollow">https:&#x2F;&#x2F;coderwall.com&#x2F;p&#x2F;vngr0a&#x2F;simple-full-text-search-using...</a><p>EDIT: Found my answer<p><a href="https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;15884309&#x2F;postgresql-full-text-search-and-trigram-confusion" rel="nofollow">https:&#x2F;&#x2F;stackoverflow.com&#x2F;questions&#x2F;15884309&#x2F;postgresql-full...</a>
ilitiritover 5 years ago
I used this to replace an aging ElasticSearch implementation our company was using. Simple and fast, and 1 less piece of tech in the stack to maintain. Postgres really is a brilliant piece of software. Yeah I know paid solutions which arguably work better exist, but for a &quot;free&quot; product Postgres does astoundingly well in many areas.
nieveover 5 years ago
I&#x27;m somewhat confused why the author didn&#x27;t use bind variables since as far as I know the standard PostgreSQL adapters fully support them. Even if you trust that quote_string() will never have a vulnerability it&#x27;s safer to not use string interpolation at all and it doesn&#x27;t cost you anything.
评论 #21579707 未加载
stanislavbover 5 years ago
Nice one. Postgres trigrams are definitely a powerful feature. I&#x27;ve written on this topic as well <a href="https:&#x2F;&#x2F;dev.to&#x2F;saashub&#x2F;postgres-trigram-indexes-vs-algolia-1oma" rel="nofollow">https:&#x2F;&#x2F;dev.to&#x2F;saashub&#x2F;postgres-trigram-indexes-vs-algolia-1...</a>
pmontraover 5 years ago
Oh wow, thanks to this post I learned that SQL has &quot;order by &lt;number&gt;&quot;, the index of the column in the select list. That after 30 years of SQL...
评论 #21579306 未加载
bgormanover 5 years ago
This is a really powerful feature. Combined with metaphone&#x2F;soundex you can have a nice lightweight fuzzy+phonetic search using vanilla postgres.
nooyurrsdeyover 5 years ago
Nicely written and easy to follow. Also more proof that you don&#x27;t need a specialized library &#x2F; dependency for every thing - sometimes you can get most of the way there with a few lines of your own code.