Firstly I would like to say how brilliant Full Text Search (FTS) is. Many thanks Couchbase and the community.
Is it possible for the FTS API to return the contents of the matching documents rather than just the document id?
The API at http://developer.couchbase.com/documentation/server/4.5/rest-api/rest-fts-indexing.html#topic_hpd_2y4_1v__p-api-index-name-query doesn’t appear to list all the possible options.
Are there any plans to allow FTS to be accessed via the Sync Gateway?
Worked it out! The ‘fields’ property can be an array of the document fields you want to return with FTS. However it only returns matching document fields which are part of the FTS index.
Is there to return document fields which are not part of the FTS index?
FTS supports stored fields, which is one easy way to get what you’re after. When you create a full text index, you can optionally copy the actual data from the document into the index itself if you want to. Normally, you don’t need to because you still have the documents themselves in Couchbase, and you can always do a get in your application to retrieve them. Below is a picture that’ll help you find the setting to enable “store” when you create an index. It’s a setting at the field level, and you can even enable it for the whole index if you go to “advanced”. Obviously, doing this takes up more space in the index but it’s the only way in this version to get result snippets and highlighting back.
This is covered in more detail in the documentation. Here’s the part about creating full text indexes. Let me know if that helps.
Thank you so much for detailed information on the store feature. This is great and just what I need.
Is there a work around to get documents from FTS search apart from storing few fields in index? (Asking after 4years) Did anything better got included for this scenario?
@dstyle FTS will only return document IDs as part of search results.
Like you mention - “store”-ing the fields in the index definition will allow for the service to return the field (if stored) content along with the document IDs.
You can do a READ(…) on the couchbase bucket with the document ID to get back the entire document.
@abhinav Hey am I pretty new to this … uhhm TY for the response! I get your approach, but is there any way to read documents in one shot from the list of doc Ids that I get as response instead of iterating over each doc ID and getting that doc?
If the content of only certain fields from your documents is of interest, I’d recommend “store”-ing those fields to get the content of interest directly alongside your search hits. Be advised that this will cause your index’s size to grow a bit.
Using the SDK, you will need to iterate over all document IDs to retrieve the entire document content. Here’s documentation on all supported SDKs … https://docs.couchbase.com/home/sdk.html