The Image above is the structure of a part of my graph database.
What I'm trying to achieve here is that I'm trying to search for product vertices by using the name of the of their related detail vertices.
The Expected output is a list of products with their details that has a name of test3.
I am using choose step in my query to handle different values of my vertices.
g
.V()
.has('label',
within(
'data_computed_property',
'data_variable','recipe_ingredient',
'cost_setting_variable','benefit_analysis_variable',
'formula',
'detail'
)
)
.has('name', 'test3') // this is where i filter out all the detail vertices with a name of `test3`
.where(
__.in()
.has('label',
within(
'product',
'recipe',
'machine'
)
)
.in()
.has('id', '13eec000-78fa-41fd-856b-bbc37711b1f0')
)
.project('parent','property')
.by(
__.in()
.has('label',
within(
'product',
'recipe',
'machine'
)
)
.valueMap(true)
)
.by(
choose(values('label'))
.option(
'detail',
project('detail','value')
.by(valueMap(true))
.by(
choose(values('type'))
.option('string', values('value'))
.option('number', values('value'))
.option('date', values('value'))
.option('formula', out('value').valueMap(true))
.option('condition', out('value').valueMap(true))
.option('variable', out('value').valueMap(true))
.option('element', out('value').valueMap(true))
)
)
.option('data_computed_property', valueMap(true))
.option('data_variable', valueMap(true))
.option('recipe_ingredient', valueMap(true))
.option('cost_setting_variable', valueMap(true))
.option('benefit_analysis_variable', valueMap(true))
.option('formula', valueMap(true))
)
And this is the output of my query
array:2 [
0 => array:2 [
"parent" => array:3 [
"id" => "bee7eaa1-ad6c-436e-9000-7bf4665552d9"
"label" => "product"
"name" => array:1 [
0 => "Product 1"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "1235455"
]
]
"property" => array:2 [
"detail" => array:6 [
"id" => "5ad33864-25a7-424a-ba8d-a1b3e255d0a9"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "date"
]
"pk" => array:1 [
0 => "bee7eaa1-ad6c-436e-9000-7bf4665552d9/detail"
]
"value" => array:1 [
0 => 1583884800
]
]
"value" => 1583884800
]
]
1 => array:2 [
"parent" => array:3 [
"id" => "25c4cdfd-1845-4696-a427-5814d7adf71c"
"label" => "product"
"name" => array:1 [
0 => "Product 2"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "2569885"
]
]
"property" => array:2 [
"detail" => array:5 [
"id" => "db15ff37-4b13-4520-8e72-ae9f559f0fdc"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "variable"
]
"pk" => array:1 [
0 => "25c4cdfd-1845-4696-a427-5814d7adf71c/detail"
]
]
"value" => 1583884800
]
]
]
As you can see, the value property for the last element of list is a value that belongs to the first item.
This is how the output is expected to look like
array:2 [
0 => array:2 [
"parent" => array:6 [
"id" => "bee7eaa1-ad6c-436e-9000-7bf4665552d9"
"label" => "product"
"name" => array:1 [
0 => "Product 1"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "1235455"
]
]
"property" => array:2 [
"detail" => array:6 [
"id" => "5ad33864-25a7-424a-ba8d-a1b3e255d0a9"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "date"
]
"pk" => array:1 [
0 => "bee7eaa1-ad6c-436e-9000-7bf4665552d9/detail"
]
"value" => array:1 [
0 => 1583884800
]
]
"value" => 1583884800
]
]
1 => array:2 [
"parent" => array:3 [
"id" => "25c4cdfd-1845-4696-a427-5814d7adf71c"
"label" => "product"
"name" => array:1 [
0 => "Product 2"
]
"description" => array:1 [
0 => ""
]
"pk" => array:1 [
0 => "13eec000-78fa-41fd-856b-bbc37711b1f0"
]
"sku" => array:1 [
0 => "2569885"
]
]
"property" => array:2 [
"detail" => array:5 [
"id" => "db15ff37-4b13-4520-8e72-ae9f559f0fdc"
"label" => "detail"
"name" => array:1 [
0 => "test3"
]
"type" => array:1 [
0 => "variable"
]
"pk" => array:1 [
0 => "25c4cdfd-1845-4696-a427-5814d7adf71c/detail"
]
]
"value" => [
"id" => "63b66993-cb5e-4cdb-b7c4-5db069106ac3"
"label" => "cost_setting_variable"
"name" => array:1 [
0 => "07/24/2021-variable"
]
"value" => array:1 [
0 => "50"
]
"pk" => array:1 [
0 => "4837194c-fe11-485a-9ef2-54fc0d621059"
]
]
]
]
]
I have 2 entities with a one-to-many relationship. I need to select the name from both entity 1 and entity 2
$qb
->select(['f.name1', 'c.name2'])
->from('BundleOne:EntityOne', 'c')
->innerJoin('c.EntityTwo', 'f');
return $qb->getQuery()->getArrayResult();
With the above query, I get the following results:
1 => array:2 [
"name1" => "xyz"
"name2" => "n1"
]
2 => array:2 [
"name1" => "xyz"
"name2" => "n2"
]
3 => array:2 [
"name1" => "abc"
"name2" => "n3"
]
4 => array:2 [
"name1" => "abc"
"name2" => "n4"
]
As you can notice, since this is a one-to-many relationship, a name1 can have several name2 associated with it and instead of the above, I want to return the result as follows:
"xyz" => array:2 ["n1", "n2"]
"abc" => array:2 ["n3", "n4"]
that is the name1 as the key of the array that contains all name2
Is that possible?
You could do it like this (you didn't provide any real-world example of entities, so I created two on my own, just for the sake of simplicity):
#Category 1-N Product
#AppBundle/Repository/CategoryRepository.php
public function getProducts()
{
$qb = $this
->createQueryBuilder('c')
->select('c, p')
->leftJoin('c.products', 'p')
;
return $qb->getQuery()->getArrayResult();
}
Then in the controller:
#AppBundle/Controller/DefaultController.php
public function indexAction()
{
$categories = $this->getDoctrine()->getRepository('AppBundle:Category')->getProducts();
$results = [];
foreach($categories as $category) {
$results[$category['name']] = $category['products'];
}
return $this->render('...', [
'results' => $results,
]);
}
The results will be displayed like this:
array:2 [▼
"category1" => array:3 [▼
0 => array:2 [▼
"id" => 1
"name" => "product1"
]
1 => array:2 [▼
"id" => 2
"name" => "product2"
]
2 => array:2 [▼
"id" => 3
"name" => "product3"
]
]
"category2" => array:2 [▼
0 => array:2 [▼
"id" => 4
"name" => "product1"
]
1 => array:2 [▼
"id" => 5
"name" => "product2"
]
]
]
i've a timeseries in elasticsearch
{
"#timestamp" => 2017-04-11T12:53:16.000Z,
"#version" => "1",
"idx" => "915",
"type" => "testrecord",
"timestamp" => "1491915196"
}
{
"#timestamp" => 2017-04-11T12:53:16.000Z,
"#version" => "1",
"idx" => "715",
"type" => "testrecord",
"timestamp" => "1491915196"
}
{
"#timestamp" => 2017-04-11T12:53:16.000Z,
"#version" => "1",
"idx" => "609",
"type" => "testrecord",
"timestamp" => "1491915196"
}
what i want to do is to show the absolut values in kibana as a timeline means on the x-axis the timestamp on the y-axis the value of idx.
i've searched and tried but except aggregations and counts i didn't find any solution to this quite simple approach in kibana!
In julia I have a dictionary that can contains other dictionaries, lists of strings/numbers, lists of dictionaries, strings/numbers, and ranges.
I need a list containing all the possible combination of dictionaries for every range (like StepRange, FloatRange, UnitRange) it's contained in it.
Example:
Dict{}("A" => Dict{}("B" => 1:1:3, "C" => 2), "B" => [Dict{}( "S" => 1:1.1:2.1)])
=>
[
Dict{}("A" => Dict{}("B" => 1, "C" => 2), "B" => [Dict{}( "S" => 1.1)]),
Dict{}("A" => Dict{}("B" => 2, "C" => 2), "B" => [Dict{}( "S" => 1.1)]),
Dict{}("A" => Dict{}("B" => 3, "C" => 2), "B" => [Dict{}( "S" => 1.1)]),
Dict{}("A" => Dict{}("B" => 1, "C" => 2), "B" => [Dict{}( "S" => 2.1)]),
Dict{}("A" => Dict{}("B" => 2, "C" => 2), "B" => [Dict{}( "S" => 2.1)]),
Dict{}("A" => Dict{}("B" => 3, "C" => 2), "B" => [Dict{}( "S" => 2.1)])
]
Right now, I'm overloading a recursive function like this, but have no idea on how to continue.
function iterate(generic, nets::Array)
return (generic, false)
end
function iterate(range::Union{StepRange,FloatRange,UnitRange}, nets::Array)
return (collect(range), true)
end
function iterate(array::Array, nets::Array)
for (n, v) in enumerate(array)
res = iterate(v, nets)
if res[2]
## We found a range! Return it
return res
end
end
return (array, false)
end
function iterate(dict::Dict, nets::Array)
for (k, v) in dict
res = iterate(v, nets)
if res[2]
return (dict, true)
end
end
return (dict, false)
end
(I have already done this in python, but working on piece of text, using regex to find custom-defined ranges (like "[1,2,0.1]") and after generating the text code parsing it.)
The following snippet reproduces the output in the example, and it could serve as a basis for other variants which treat the recursion differently (there are many options, as I noticed when trying this out). It using Iterators.jl which is installed with Pkg.add("Iterators").
using Iterators
function findranges{K}(sd::Dict{K})
ranges = Vector{Vector}()
for v in values(sd)
if isa(v,Range)
push!(ranges,collect(v))
elseif isa(v,Dict)
push!(ranges,recdictcollect(v))
elseif isa(v,Vector)
push!(ranges,map(x->vcat(x...),collect(product(map(recdictcollect,v)...))))
end
end
ranges
end
function recdictcollect{K}(sd::Dict{K})
ranges = findranges(sd)
if length(ranges)==0
cases = [()]
else
cases = product(ranges...) |> collect
end
outv = Vector{Dict{K,Any}}()
for c in cases
newd = Dict{K,Any}()
i = 1
for (k,v) in sd
if any([isa(v,t) for t in [Range,Dict,Vector]])
newd[k] = c[i]
i += 1
else
newd[k] = v
end
end
push!(outv,newd)
end
return outv
end
And the example:
julia> example = Dict{}("A" => Dict{}("B" => 1:1:3, "C" => 2), "B" => [Dict{}( "S" => 1:1.1:2.1)])
Dict{ASCIIString,Any} with 2 entries:
"B" => [Dict("S"=>1.0:1.1:2.1)]
"A" => Dict{ASCIIString,Any}("B"=>1:1:3,"C"=>2)
julia> recdictcollect(example)
6-element Array{Dict{ASCIIString,Any},1}:
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>1.0)],"A"=>Dict{ASCIIString,Any}("B"=>1,"C"=>2))
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>2.1)],"A"=>Dict{ASCIIString,Any}("B"=>1,"C"=>2))
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>1.0)],"A"=>Dict{ASCIIString,Any}("B"=>2,"C"=>2))
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>2.1)],"A"=>Dict{ASCIIString,Any}("B"=>2,"C"=>2))
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>1.0)],"A"=>Dict{ASCIIString,Any}("B"=>3,"C"=>2))
Dict{ASCIIString,Any}("B"=>[Dict{ASCIIString,Any}("S"=>2.1)],"A"=>Dict{ASCIIString,Any}("B"=>3,"C"=>2))
How to display Sub categories of main categories in wordpress? like
Categories
Sub Categories 1
Sub Categories 2
You can do that by using the get_categories function. Like this:
<?php
$cat = get_categories(array('child_of' => 3));
var_dump($cat);
?>
The child_of parameter is the ID of the parent category. It will return all the sub categories of that parent category.
Sample output:
array(2) {
[0]=>
object(stdClass)#74 (15) {
["term_id"]=>
&string(1) "4"
["name"]=>
&string(19) "Child 1 of Parent 1"
["slug"]=>
&string(16) "child-1-parent-1"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(1) "4"
["taxonomy"]=>
string(8) "category"
["description"]=>
&string(0) ""
["parent"]=>
&string(1) "3"
["count"]=>
&string(1) "1"
["cat_ID"]=>
&string(1) "4"
["category_count"]=>
&string(1) "1"
["category_description"]=>
&string(0) ""
["cat_name"]=>
&string(19) "Child 1 of Parent 1"
["category_nicename"]=>
&string(16) "child-1-parent-1"
["category_parent"]=>
&string(1) "3"
}
[1]=>
object(stdClass)#114 (15) {
["term_id"]=>
&string(1) "5"
["name"]=>
&string(19) "Child 2 of Parent 1"
["slug"]=>
&string(16) "child-2-parent-1"
["term_group"]=>
string(1) "0"
["term_taxonomy_id"]=>
string(1) "5"
["taxonomy"]=>
string(8) "category"
["description"]=>
&string(0) ""
["parent"]=>
&string(1) "3"
["count"]=>
&string(1) "1"
["cat_ID"]=>
&string(1) "5"
["category_count"]=>
&string(1) "1"
["category_description"]=>
&string(0) ""
["cat_name"]=>
&string(19) "Child 2 of Parent 1"
["category_nicename"]=>
&string(16) "child-2-parent-1"
["category_parent"]=>
&string(1) "3"
}
}
First you need to parent category id then you can get its sub category from table wp_term_taxonomy
<?php global $wpdb;$prefix=$wpdb->prefix;
$subcateogyr_list=$wpdb->get_results("Select * from ".$prefix."term_taxonomy WHERE parent='parent_category_id'");
foreach($subcateogyr_list as $subcat
echo $subcat_name=$wpdb->get_var("select name from ".$prefix."wp_terms where term_taxonomy_id='$subcat['term_id']'");
}
?>