ACF filtering data by meta query - advanced-custom-fields

I have an api url, I don't really have an access to the code as I'm the front end guy. I came across this json format:
"acf": {
"abc": {
a: "11",
b: "12"
},
"test": true
}
So if I want to filter results by test = true I can modify my query like this:
meta_query[0][key]=test&meta_query[0][compare]=like&meta_query[0][value]=1
What if I want to filter by abc.a value = 11? What would be the query? Thanks in advance.

Related

JSON query matching

For the given input JSON:
{
"person": {
"name": "John",
"age": 25
},
"status": {
"title": "assigned",
"type": 3
}
}
I need to build a string query that I could use to answer if the given JSON matches it or not. For example if the given person's name is "John" and his age is in the range of 20..30 and his status is not 4.
I need the query to be presented as a string and a commonly known library that can run it. I need it on multiple platforms (iOS, Android, Xamarin). I've tried JSON Path and JSON schemas, but didn't really figure out if it's able to achieve that with them. JSON Path seems to be specified on finding a single value in the JSON by a certain condition and JSON Schema mostly checks for the data structure and types.
Ok, found the solution. If I format the whole input object as a single-element array like that:
[
{
"person": {
"name": "John",
"age": 25
},
"status": {
"title": "assigned",
"type": 3
}
}
]
That will allow me to use JSON Path expressions:
$[?(#.person.name == 'John' && #.person.age >= 20 && #.status.type != 4)]
Basically if it doesn't match there won't be a result.

Incompatible value for Quickbase Date Field

I have a feature where I update the values on Quickbase for our system.
I am able to update most fields, checkboxes, text inputs and numerical data..
using this kind of query
{
"to":"appid",
"data": [
{
"3": { "value": 1 },
"308": { "value": "2021-5-17" },
"104": { "value": true }
}
]
}
but when I try updating a value on a date field.. I get a '207 Multi-Status' response from it.
any idea how to set date values?
I tried different string formats. Quickbase formulas/functions like 'today()'
Thanks!
The format of your date is not quite correct. This API is very strict about the format YYYY-MM-DD so you should use "308": { "value": "2021-05-17" }. You can use some other keywords such as today for the value as described in the field type documentation. Also, if you are actually using the application Id for appId that will also cause problems since a table ID is expected there instead.
There could be other errors and the 207 Multi-Status code alone doesn't give much of a hint about what went wrong. If you can, look at the response body where you should see an error description returned from Quickbase that would look something like this:
{
"data": [],
"metadata": {
"createdRecordIds": [],
"lineErrors": {
"1": [
"Incompatible value for field with ID \"308\"."
]
},
"totalNumberOfRecordsProcessed": 1,
"unchangedRecordIds": [],
"updatedRecordIds": []
}
}

Use Doctrine to search into a json database column

I have a Symfony 3.2 project, and I need to filter data from a json column.
Given that we have an entity named "pack" with a json column named "settings" containing this kind of data:
{
"name": "My pack",
"blocks": [
{
"name": "Block 1",
"fields": [
{"label": "A", "value": "57"},
{"label": "B", "value": "100"}
]
},
{
"name": "Bock 2",
"fields": [
{"label": "C", "value": "80"}
]
}
]
}
I have to search packs with a field which has the label "B" and its value at "100", but each pack doesn't have same blocks and fields order.
So in my repository, using Doctrine\ORM\EntityRepository and opsway/doctrine-dbal-postgresql (for GET_JSON_FIELD and GET_JSON_OBJECT functions), this kind of condition works:
use Doctrine\ORM\EntityRepository;
class Packs extends EntityRepository
{
public function findFiltered(...)
{
return $this->createQueryBuilder('pack')
->andWhere("GET_JSON_FIELD(GET_JSON_OBJECT(pack.settings, '{blocks,0,fields,1}'), 'label') = :label")
->andWhere("GET_JSON_FIELD(GET_JSON_OBJECT(pack.settings, '{blocks,0,fields,1}'), 'value') = :value")
->setParameter('label', 'B')
->setParameter('value', '100')
;
}
}
But the problem is that I have to specify the precise block (the first block object), and the precise field (the second field object of the first block object). And my two condition aren't connected, it search if there is a label "B", then it search if there is a value "100". When I would like to have a research in all blocks and fields to find the good label for the good value. Any idea?
I found the good SQL request for my problem:
SELECT *
FROM pack p, json_array_elements(p.settings#>'{blocks}') blocks, json_array_elements(blocks#>'{fields}') fields
WHERE fields->>'label' = 'B' and fields->>'value' = '100';
But how I do that with doctrine?
Maybe this link can help you, it is a custom filter for a JSON type field, maybe it will serve as an example, but these functions with this bundle solved the problem for me. I hope this helps someone else too. Cheers!

Testing an utterance: comparison to "published" produces JSON string completely different from results obtained by querying the API

I just trained my LUIS application and published it to production. If I test it on an utterance, I can see how that result compares to the published version and look at the JSON result. The problem is I'm getting a completely different JSON result there than I get when I query the API via its URL. Here is the test result JSON:
{
"query": "please show me *johnson*",
"prediction": {
"normalizedQuery": "please show me *johnson*",
"topIntent": "Show",
"intents": {
"Show": {
"score": 0.985523641
}
},
"entities": {
"ShowObject": [
"*johnson*"
],
"$instance": {
"ShowObject": [
{
"type": "ShowObject",
"text": "*johnson*",
"startIndex": 15,
"length": 9,
"score": 0.8382344,
"modelTypeId": 1,
"modelType": "Entity Extractor",
"recognitionSources": [
"model"
]
}
]
}
}
}
}
and here is the API query result:
{
"query": "please show me *johnson*",
"topScoringIntent": {
"intent": "Show",
"score": 0.985523641
},
"intents": [
{
"intent": "Show",
"score": 0.985523641
}
],
"entities": [
{
"entity": "* johnson *",
"type": "ShowObject",
"startIndex": 15,
"endIndex": 23,
"score": 0.8382344
}
]
}
The problem with the API query result is that it doesn't return enough information about the entity, and it returns a different entity than the test result. Note above that the test result returns *johnson* with no spaces near the asterisks, which is how the original query is, but the API query result returns * johnson * with spaces near the asterisks. I don't want it to put the spaces in, so I prefer the test result over the API query result.
Why are they different, and how do I get the API query to return a result like the test, i.e. with no modification of the input string to add spaces near the asterisks.
Here is the API query URL including parameters:
https://westus.api.cognitive.microsoft.com/luis/v2.0/apps/[app ID removed]?q=please+show+me+*johnson*&timezoneOffset=0&verbose=true&spellCheck=false&staging=false
Oh, I see now - this is probably to represent a wildcard search, right? If so, I'm not personally aware of a way to strip this out of a LUIS response, and I've seen similar, I think, when there's an #mention in there as well. However, if this is to facilitate searches, such that you know there's a good chance to have a * before and/or after the "ShowObject" entity, then it should be easy enough to test for this and replace, either string or regex (replace the "star-plus-space" with a space, I mean - I realise you need the star itself). Basically, you'd replace "[start][space]" with "[start]", and same at the end. Not pretty, but workable and simple to implement...
Just out of interest, do you anticipate * in the middle of a string as well?

What is the fastest way to iterate through a dictionary's value in python?

So, I would like to know what is the fastest way to iterate through a dictionary's value and compare it's value to another variable. I have a specific dictionary stucture which is really simple:
"data": [
{
"id": "xxxxxxxxxxxxx"
},
{
"id": "xxxxxxxxxxxxx"
},
{
"id": "xxxxxxxxxxxxx"
},
{
"id": "xxxxxxxxxxxxx"
},
{
"id": "xxxxxxxxxxxxx"
},
{
"id": "xxxxxxxxxxxxx"
}
]
I already loop through some_dict['data'] and then compare it's ['id'] value using this code:
for item in some_dict:
if item['id'] == some_value:
#do stuff
But with a large size dictionary, it takes a lot of time so I was curious about other ways to do what i wanted. I heard of set which are good for huge list iteration but is there anyway to use it from my dict structure?
As I see it, your way is OK. But if you insist on a different way then you can do:
from itertools import chain
flat_list = list(chain.from_iterable([d.values() for d in some_dict['data']]))
for item in flat_list:
if item == some_value:
# do stuff
Or, if you only want to check for presence:
if some_value in flat_list:
# do stuff
About set, if there are duplicates in the id's values, it will eliminate them. So unless thats fine by you, I wouldn't use it.