how to get list of attributes from a JSONata query - jsonata

I want to know for the given JSONata query how can we find out list of attributes with their path. Is there any any API/function to get some metadata about the query. For e.g. for the following query I want to find out the attribute name as "Account.Order.Product.Price" and "Account.Order.Product.Quantity"
$sum(Account.Order.Product.(Price * Quantity))
This may not be simple Regx or string parsing as query can contain functions & operators as well.
Atul

Related

Search specific key's value from a json field database entry using eloquent

Hello everyone please I am working on a system and need to add a query that receives a search term stored with the variable $search and fetch all matching values for a specific key in a json field from database.
I have tried the code bellow
$query = Book::whereJsonContains('book_details->author',['like'=>"%{$search}%"])->get();
Book is my model, book_details is the json field name and author is the key. I want to retrieve every book with authors related to the search term
In Laravel, you can perform a query that retrieves all matching values for a specific key in a JSON field by utilizing the whereJsonContains method. A revised version of your code could look like this:
$query = Book::whereJsonContains('book_details->author', $search)->get();
This query will return all Book records where the value of the author key in the book_details JSON field contains the search term stored in the $search variable.
Note that you don't need to wrap the search term in % characters, as the whereJsonContains method performs a case-insensitive search for matching values by default.

How to search an array element in SurrealDB

I'm trying to perform a query that evaluates if an array includes or contains a specif value or set of values.
SELECT * FROM table
WHERE data = ['value_a']
https://surrealdb.com/docs/surrealql/statements/select
I've read the documentation and try several queries, but I didn't find any function or way to create this query.
I've read the official documentation and performed several queries based on the examples, but nothing have worked.
https://surrealdb.com/docs/surrealql/statements/select
My expected behaviour is:
Matches a specific value or set of values like these examples in SQL relational database.
https://www.w3schools.com/sql/sql_in.asp
There is a CONTAINS operator :
https://surrealdb.com/docs/surrealql/operators#contains
The Query should be like:
SELECT * FROM table WHERE data CONTAINS 'value_a'

Use a Field value in a Query (Seblod Query plugin)

I'm using the Query plugin that lets me create a Query field on my List & Search.
I have a hidden field with ID 'id_number' which I'm trying to use in my query. When I check the Page Source(Ctrl+U on Chrome), the hidden field has the correct value of id_number which is '22865'.
The part of my Query is-
WHERE [MATCH]p.pid||$cck->getValue('id_number')[/MATCH] AND (ban_reason in ("", "active"))
When I print this query out using the Debugger, the Query is using the literal value and querying the above as-
(p.pid LIKE '%$cck->getValue(\'id\_number\')%') ....and not like (p.pid LIKE '%22865%')
I also tried using $fields['id_number']->value but it still queries it incorrectly.
Should I not use $cck->getValue('id_number') to get the value of the hidden field in the query? Or is there something other than this that I need to use?

JSONata : walk tree and return all object names

JSONata has the $keys() function which returns all the names associated with an object. I am trying to recursively apply this in order to return all of the object names that exist in a JSON tree.
This example returns the object names in nested arrays.
In an attempt to eliminate the array nesting I came up with this query ... which seems to work fine.
However, when I apply the exact same query to different JSON data as shown here the results are not fully flattened.
Q: What is the proper way to construct this query so that the results are fully flattened?
and/or
Q: What characteristic distinguishes these two datasets to account for the difference in the structure of the results?
OK, I guess I figured this out.
This query uses explicit calls to $map() and $reduce()+$append() to flatten it.
This query accomplishes the same thing using more a standard JSONata dot (.) query notation.

How to query elasticsearch without specifying which property to match

I have an elasticsearch document with multiple properties, like title, body, author.
I'd like to get results from a query that matches ANY of the fields.
Usually, I'll query by specifying a property to match. I'd rather write a more flexible query that will return the whole document if any of the properties are matched.

Resources