Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

full text indexing of recursive nested jsonb structures

Lets say I have a book represented like this:

{ title: "Tis no book"
  chapter: 1,
  text: "Hello world this is a book chapter",
  subchapters: [
     {
     chapter: 1.1
     text: "Nested sub chapter"
     subchapters: [
       chapter: 1.1.1
       text: "Nested nested..."
       subchapters: [ ...etc...]
     },
     {
     chapter: 1.2
     text: "Nested sub chapter 2"
     subchapters: [ ...etc...]
     }
   ]
}

Can I use postgres' 9.4 new jsonb/gin (or anything else) to set up a full text index on the "text" field of this recursively nested data structure such that a library of books stored to the database can be searched by text (using the index)?

like image 608
gremwell Avatar asked Mar 23 '15 11:03

gremwell


1 Answers

I have just started looking into full-text search and jsonb types. It looks like this is possible once you understand how the indexes work on JSONB types. I have found this blog series to be very helpful.

https://bibhas.in/blog/postgresql-swag-part-2-indexing-json-data-type-and-full-text-search/

Also, the documentation on the JSON type at Postgres contains some good insights. http://www.postgresql.org/docs/9.4/static/datatype-json.html

like image 169
Thomas Wayne Shelton Avatar answered Sep 26 '22 06:09

Thomas Wayne Shelton