Skip to content

Commit

Permalink
Support json query with "where: <boolean>"
Browse files Browse the repository at this point in the history
  • Loading branch information
hmusum committed Jan 18, 2025
1 parent 9958447 commit 4a84b9f
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@
package com.yahoo.search.query;

import com.google.common.base.Preconditions;
import com.yahoo.prelude.query.FalseItem;
import com.yahoo.prelude.query.TrueItem;
import com.yahoo.processing.IllegalInputException;
import com.yahoo.collections.LazyMap;
import com.yahoo.geo.DistanceParser;
Expand Down Expand Up @@ -63,6 +65,7 @@
import static com.yahoo.search.yql.YqlParser.MAX_EDIT_DISTANCE;
import static com.yahoo.search.yql.YqlParser.PREFIX_LENGTH;
import static com.yahoo.slime.Type.ARRAY;
import static com.yahoo.slime.Type.BOOL;
import static com.yahoo.slime.Type.DOUBLE;
import static com.yahoo.slime.Type.LONG;
import static com.yahoo.slime.Type.OBJECT;
Expand Down Expand Up @@ -181,6 +184,9 @@ private QueryTree buildTree() {
}

private Item walkJson(Inspector inspector) {
if (inspector.type() == BOOL)
return inspector.asBool() ? new TrueItem() : new FalseItem();

Item[] item = {null};
inspector.traverse((ObjectTraverser) (key, value) -> {
String type = (FUNCTION_CALLS.contains(key)) ? CALL : key;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,12 @@ void test_contains() {
assertParse(json.toString(), "default:foo");
}

@Test
void testWhereWithBoolean() {
assertParse("true", "TRUE");
assertParse("false", "FALSE");
}

@Test
void testDottedFieldNames() {
assertParse("{ 'contains' : ['my.nested.title', 'madonna']}",
Expand Down

0 comments on commit 4a84b9f

Please sign in to comment.