<i>To get optimum performance with PostgreSQL full text search you need to create a column to store the tsvector values with an index on it. Then you need to fill this column with the tsv values and create a trigger to update the field on INSERT and UPDATE.</i><p>I've been playing around with full text search in Postgres, and I took this sort of approach when starting out, but then realized you I could just have the index be an expression.<p>So instead of (per the example)<p><pre><code> CREATE INDEX tsv_idx ON documents USING gin(tsv);
</code></pre>
doing something like<p><pre><code> CREATE INDEX tsv_idx ON documents USING gin(to_tsvector('english', text));
</code></pre>
Is there any reason you <i>wouldn't</i> do this? For multi-languange you you'd have to detect the language of the text, but there's no reason you couldn't parameterize that too.
> This query takes about 50ms! We experimented with returning the document text with results and found that if we returned the full text of documents, it added about 350ms to the query time which seems to be network overhead rather than a slower query. If we only returned 200 characters from the texts then it only added around 100ms.<p>The way you have written the query, it has to extract the title from all of the JSON documents before applying the LIMIT.<p>Perhaps do the work to get the identifiers, order by rank, and apply the limit... all in a subquery. So that only the outer query actually touches the JSON document and extracts the titles.<p>Try it and report back on the speed improvement.
Sure, if you only need full text search there's no need to use Solr or ElasticSearch.<p>I've never tried with PostgreSql, but I noticed the same drop in performance in MySql at the 1-2 million documents count, although full text search queries in MySql are slower (from what I remember, I haven't tested in a couple of years).<p>The power of Solr and other tools out there is all the other stuff you can do, like synonyms processing, faceting, range queries, etc, etc... as well as give you more flexibility on what data you load and how you process it. But if you don't need it, there's no reason to use a different tool.
"The accuracy of PostgreSQL searches is not the best. In the examples that follow I’ve explained how to weight titles over text, but we found a few cases where typing the exact title of a document wouldn’t return that document as the first result."<p>Isn't this a concern as the main objective of search is to provide accurate results?
Nice writeup, I wrote a similar blog post a few years ago: <a href="http://tech.pro/tutorial/1142/building-faceted-search-with-postgresql" rel="nofollow">http://tech.pro/tutorial/1142/building-faceted-search-with-p...</a><p>Mine covers tags and other aspects of faceted search as well.<p>We were able to build a really simple search facility for our marketplace using Postgres in a very short period of time and for cheap. It was incredibly helpful for a small startup short on people and resources.
Naive question from a person with little DB experience: Why store the metadata in JSON inside the database instead of in multiple columns in the same table? Is this not the point of using a database?
> The main arguments against using PostgreSQL search are accuracy and speed at scale.<p>Also, lack of faceted search, phrase search, partial word search (although you could use pg_trgm)<p>Previous 2 related discussions:
- <a href="https://news.ycombinator.com/item?id=8381748" rel="nofollow">https://news.ycombinator.com/item?id=8381748</a>
- <a href="https://news.ycombinator.com/item?id=8714477" rel="nofollow">https://news.ycombinator.com/item?id=8714477</a>
I tried using Postgres 9.4 full-text search for my forum, but ran into some "column wider than full-text index" error (don't remember the exact issue). Wasn't running into any of these: <a href="http://www.postgresql.org/docs/8.3/static/textsearch-limitations.html" rel="nofollow">http://www.postgresql.org/docs/8.3/static/textsearch-limitat...</a><p>Googling the error lead me to a mailing list where someone was "working on it" or "going to revert the problem soon".<p>Ended up using AWS CloudSearch which costs a minimum of $50/mo where I was already paying for Postgres.
PostgreSQL is coming up a lot and making waves, never thought much about it until recently it turns out to be more reliable than mongodb. Interesting phenomena.
Seems sketchy.<p>While Postgres <i>can</i> do full text search and it <i>may</i> help you in your case, you can set up Elasticsearch for this sort of quantity of data in like an afternoon, if that.<p>Also, these 'advanced features' people are throwing around are really trivial; they're the sort of things that would crop up in lecture 2 of an information retrieval course. Good search is really reliant on proper weighting etc (not like 'we weight the title more highly than the body' but more 'foogle is a far more important word than bar, if we have both in a query, we care about foogle more'). This generally requires a tonne of experimentation; information retrieval is not easy and it's very subtle.<p>Postgres seems to try and make everyone design their own ranking function, which is a recipe for disaster. I haven't used Elasticsearch for a while, but I'd be surprised if they didn't have a bunch of relatively good presets.<p>Postgres is good for loads of things, but Elasticsearch or Solr are state-of-the-art and Postgres isn't (so far as I know); if you aren't just hacking around then <i>please</i> consider the extra time to set up Elasticsearch and it'll make your life easier.