Getting Issue with ArrayExpression

java

#1

Hi,

I am trying to access inner object with the below written query but i am not able to understand what i am doing wrong.

    query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
                    .where(ArrayExpression.any(ArrayExpression.variable("SYNONYMS")).in(Expression.property("synonymsTest"))
  .satisfies(Function.lower(ArrayExpression.variable("SYNONYMS.synonyms")).like(Expression.string(term + "%")))
.or(Function.lower(Expression.property("labtest_name")).like(Expression.string(term + "%")))).limit(Expression.intValue(30));
           

Please let me know what is wrong above written query. I am trying to query below written document.

{
  "components": [
    {
      "component_name": "lactate dehydrogenase"
    }
  ],
  "labtest_name": "Serum lactate dehydrogenase",
  "synonymsTest": [
    {
      "synonyms": "serum ldh"
    },
    {
      "synonyms": "lactate dehydrogenase, serum or plasma"
    }
  ],
  "timestamp": 1515069417,
  "type": "labtest",
  "uid": "0072a140-c95b-40bd-8d0e-1aff1e6b7897"
}


#2

Couple of things

  • I think your variable definition isn’t correct. For clarity, I would recommend declaring the variables separately and then using it within your Query .
 VAR_SYNONYMSENTRY = ArrayExpression.variable("synonymsEnry")
 VAR_SYNONYMS = ArrayExpression.variable("synonymsEnry.synonyms")

query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
.where(ArrayExpression.any(VAR_SYNONYMSENTRY).in(Expression.property("synonymsTest"))
 .satisfies(Function.lower(VAR_SYNONYMS )).like(Expression.string(term + "%")))
.or(Function.lower(Expression.property("labtest_name")).like(Expression.string(term + "%")))).limit(Expression.intValue(30));

  • Also, for starters, I would start simple instead of having many conditionals w/ pattern matching. So try something a bit more straightforward and see if you get results.
query = QueryBuilder.select(SelectResult.all()).from(DataSource.database(database))
.where(ArrayExpression.any(VAR_SYNONYMSENTRY).in(Expression.property("synonymsTest"))
 .satisfies(VAR_SYNONYMS .equalTo(Expression.string("serum ldh")))

#3

@priya.rajagopal thanks for your help. Thanks alot. :+1:


#4

i got the same issue, i proceed exactly like priya said but i didn’t got any result. Please what is the problem