Like Query on Concatenation of two fields in Couchbase Lite

query
mobile

#1

Hi,

We have to create a like query on the concatenation of two fields, say First Name and Last Name on Couchbase Lite 2.1.

We are using the below query and not getting any results.
Can anyone please help.

We are using the query given below :-

String searchTerm = “%Harsh Mehlawat%”;
Query query = QueryBuilder.select(
SelectResult.property(“ID”))
.from(dataSource)
.where(Expression.property(“type”).equalTo(Expression.string(“PersonalInformation”))
.and(Expression.property(“FIRSTNAME”)
.add(Expression.string(" ")
.add(Expression.property(“LASTNAME”))
.like(Expression.string(searchTerm))
)));


#2

add is for numeric operations. There is no string concatenation operator in the query builder yet. I’d suggest doing the reverse and parsing the first and last name out of the search term and then using an and operation.


#3

we may also want to add middle name in between which will make complexity higher and produce unwanted result. Secondly search term will not be having complete data.

Better we can have a field in the document as fullName which can be concatenated while saving the data. Which makes everything easy.

But

Should become a priority feature. Along with unnest functionality.

@househippo, @priya.rajagopal, @jens should I create a ticket for this. Or it is already in backlog.

Regards
Pankaj Sharma


#4

The concatenation operator already exists in couchbase-lite-core; we’d just need to add it to the public query-builder API.


#5

Our API issue tracker isn’t public, but I’ve just filed this as an issue.


#6

Thank you @jens . Have you filed issue for both unnest and concatenation?


#7

Unnest is already in development.


#8

Please file both UNNEST and concatenation requests with specific use case description through the Accounts team. They are on our radar but your request will help with the prioritization.