here’s something that I haven’t see explained in the docs.
I’m trying to build an FTS index on a Couchbase lite database. My documents has an array of nested objects, something like:
content: "This is the text to be indexed"
content: "Yet another text"
I’m creating my FTS index like this:
The ‘name’ and ‘description’ fields are correctly indexed and I can query against them, but not the reviews’ content field. Is there a specific syntax to allow indexing of objects nested in arrays ?
This is actually invalid because you don’t have a property
reviews.content on your document. Your
reviews property is an array of objects, so
reviews.content doesn’t refer to a single property. FTS index properties must be string properties. What you would have to do in this case is instead of nesting all reviews inside the object, go more horizontal and make some review documents that have a property indicating their parent (foo in this case). Then you can FTS index the review documents since they will each have a proper
content property. As a bonus this will help with contention since right now every review requires editing the same document.
Ok thanks. So what you’re saying is that there’s no way to FTS index an array of objects nested in a doc ? OK.
Sure I can flatten the objects, that was my first thought, but the point of Couchbase is to be able to store complex objects, as opposed to SQL, and read/write them in one go.
My actual documents are pretty static, they’re never edited, so that’s not an issue: the “reviews” array is not an actual reviews array, it was just for example sake.
Another idea would be to concatenate the ‘content’ property of all the sub-objects into a first-level property, which could then be indexed. But that would double the storage space and required a second query to figure out which array element has been hit.
Or maybe there’s an alternative database that could provide this feature ? sqlite has got an FTS extension, so I could also use that. At the expense of the flexibility of NoSQL DBs.