documentType on FTS view

18 views
Skip to first unread message

Brendan Duddridge

unread,
Aug 17, 2015, 2:43:59 PM8/17/15
to Couchbase Mobile
Hi,

I don't think that documentType is supported with a CBLView that's used for a FTS query.

It would be super useful if you could specify documentType for a full text query so you only get back documents of a specific type.

This is what I'm doing in code:

CBLQuery *query = [fullTextView createQuery];

query.fullTextQuery = searchTerm;

fullTextView.documentType = self.document.documentID;


I have all of my "record" documents with a type set to be the document ID of the form the records are contained in. That's why I'm using the form's documentID as the documentType.

But when I query like this, I'm getting back documents that match other document types. So it seems to be ignoring the documentType for full text queries.

Am I doing something wrong or is this in fact the case?

Thanks,

Brendan

Jens Alfke

unread,
Aug 19, 2015, 2:01:22 PM8/19/15
to Couchbase Mobile

On Aug 17, 2015, at 11:43 AM, Brendan Duddridge <bren...@gmail.com> wrote:

It would be super useful if you could specify documentType for a full text query so you only get back documents of a specific type.

documentType is an aspect of the view, not of a query. It takes effect at indexing time, by filtering which documents get passed to the map function.

This is what I'm doing in code:

CBLQuery *query = [fullTextView createQuery];
query.fullTextQuery = searchTerm;
fullTextView.documentType = self.document.documentID;

You should set documentType before querying, ideally at the same time you set the mapBlock, so that it’s in effect when the view gets indexed.

—Jens

Brendan Duddridge

unread,
Aug 19, 2015, 2:49:37 PM8/19/15
to Couchbase Mobile
Ah, now that would explain why when I had documentType specified on my view, it was only indexing the documents for one form at a time (I need all documents indexed). I was trying to avoid having  separate FTS views for each of my forms with a given documentID. I thought if there was one view that had different documentTypes then at query time I could limit my query to just those documents. But I guess that's really what having different views is all about. 

I have two different ways I use FTS to search in my app:

1. Search for records within a specific form.
2. Search for records within ANY form. 

So I'm guessing I need a separate view for each of my individual forms, plus one big view that contains all my documents so I can do the ANY form search that I need.

Either that or I have to embed the documentID inside each of my documents in the emit statement in the map block for the view and then include that in the FTS search term.

It would be nice if there was a secondary index on an FTS view that could be used just for queries. So if that secondary index got populated with my documentID values, then I could do something like this (in SQL parlance):

select * from fullTextView where content match 'Hunger Games*' AND secondaryIndex = 'frm-ABC123456789';

Then to do my ALL query I could leave off the parameter for the secondaryIndex and that would give me back all rows that match the search term.

Back to the drawing board :-)

Thanks,

Brendan
Reply all
Reply to author
Forward
0 new messages