Hello,
I was wondering how can I search for a string containing parentheses in android Couchbase lite.
For example, if I search for
text (to) search
I won’t be able to search the correct item, due the parentheses. I’ve already tried to escape parentheses, but if I escape them this will be the resulting string:
text \(to\) serach
and it won’t match my item in the db.
Thanks in advance.
Quick question. Are you using FTS or regular query comparison?
If this is a regular query, I don’t think the backslash \ is needed. You will need \ for ". Do you have any failed cases as an example?
Regular query.
Thanks
If I search
text (to) search
and I have a row with field
containing the exact same string, applying this query won’t return anything.
QueryBuilder.select(SelectResult.all())
.from(mDatabase)
.where(
Expression.property("field").equalTo(Expression.string(string_to_search)))
);
This is .NET but I did exactly this inside of a test:
using (var foo = new MutableDocument("foo")) {
foo.SetString("field", "text (to) search");
Db.Save(foo);
}
using (var q = QueryBuilder.Select(SelectResult.All())
.From(DataSource.Database(Db))
.Where(Expression.Property("field").EqualTo(Expression.String("text (to) search")))) {
q.Execute().Count().Should().Be(1);
}
And it works fine. Is this what you are trying to say is failing?
There is absolutely nothing special about parentheses in strings, and equality tests on strings in queries just do literal comparisons. You’ll have to show us a more complete example that fails.
Are you sure that there are no other examples when it cruches?