The parsed query tree.
A Shopify search DSL string (e.g. title:*foo* AND (title:*bar* OR title:*baz*)).
translateAstToShopifyQuery({ type: "and",
left: { type: "term", value: "Carbonate", phrase: false },
right: { type: "or",
left: { type: "term", value: "Sodium", phrase: false },
right: { type: "term", value: "Potassium", phrase: false } } });
// "title:*Carbonate* AND (title:*Sodium* OR title:*Potassium*)"
export function translateAstToShopifyQuery(ast: SearchAst): string {
switch (ast.type) {
case 'term':
return termToClause(ast.value);
case 'and':
return `(${translateAstToShopifyQuery(ast.left)} AND ${translateAstToShopifyQuery(ast.right)})`;
case 'or':
return `(${translateAstToShopifyQuery(ast.left)} OR ${translateAstToShopifyQuery(ast.right)})`;
case 'not':
return `NOT ${translateAstToShopifyQuery(ast.operand)}`;
}
}
Translates a SearchAst into a Shopify Storefront search query string.