Query - get_all - Multiple Inputs - Pydgraph - dgraph

As stated over here link, it query for 'Alice' and it results for all the information for 'Alice'.
What if I have 'n' inputs in order to get all information say n=2 'Alice', 'Bob', etc.
What would be the query?
I tried to define variables_1 = {'$b': 'Alice, Bob'}
and defining $b: list in query list or array but not working.

Related

Query Importrange with concat - adding 2 of the returned columns together

I am trying to import specified data using query importrange but at the same time I want to reduce need for additional calculation columns and by using concat or something similar to add 2 columns together with a space in between ie. first name 'bob' last name 'smith' returns 'bob smith' in 1 column
=QUERY({IMPORTRANGE("https://docs.google.com/spreadsheets/d/1oaZP3-p1cI4d1QyLQ2qM5sMwnVGz8S0bhe29W4QqH6g/edit#gid=1908577977","Sheet7!A2:c"),"select Col1&" "&Col2,Col3",0})
I've tried the above but it returns formula parse error
https://docs.google.com/spreadsheets/d/1oaZP3-p1cI4d1QyLQ2qM5sMwnVGz8S0bhe29W4QqH6g/edit?usp=sharing
in post-IMPORTRANGE you can join two columns only like this:
=FLATTEN(QUERY(TRANSPOSE(QUERY(
IMPORTRANGE("13Ptmj3sejlOADvwhgfBPxRy_H-RGCxLX4r2jecbceIE", "Sheet7!A2:C"),
"select Col1,Col2", )),,9^9))
so for 3 columns:
={FLATTEN(QUERY(TRANSPOSE(QUERY(
IMPORTRANGE("13Ptmj3sejlOADvwhgfBPxRy_H-RGCxLX4r2jecbceIE", "Sheet7!A2:C"),
"select Col1,Col2", )),,9^9)),
IMPORTRANGE("13Ptmj3sejlOADvwhgfBPxRy_H-RGCxLX4r2jecbceIE", "Sheet7!C2:C")}

find query in one to many relationship

Support i have a document structure as follows
var order = {
order_id : "1234",
plan_name: "Basic plan",
app_id:["app-id-1","app-id-2"]
}
It has one to many relationship structure.
i inserted it in mongo like this
db.orders.insert(order)
I also created index on order_id and app_id.
Now , i have an app_id , i want to find its order_id.
How to write query to find
I know i need to use
db.orders.find({"app_id":""}) , but app_id is an array.
Or is there a other technique i am missing ?
You can query on arrays in several ways.
If you want to find all orders with app-id-1 as a value in the app_id array you can simply query
app_id: "app-1-id"
This will return all orders which have that value in their array.
if you want to find all orders which have a set of app ids you can query
app_id: {$all: <array_of_app_ids>}
To find all orders which contain only a specific set of ids and no others you can pair $all with $size
app_id: {$all: <array_of_app_ids>, $size: <array_of_app_ids.length>}
but if you pass a single value, mongoDB will return all entries which have that value in their array

mongodb query result sequence

Here is my query statement.
db.users.find({"_id":{"$in":[id0, id1, id2]}})
Of course it will return correct user array, but the sequence is random, it could be
[user1, user0, user2]
or
[user2, user0, user1]
it depends on ids' value.
If there is a way that I could force mongodb always return user array like this
db.users.find({"_id":{"$in":[id0, id1, id2]}}) => [user0, user1, user2]
db.users.find({"_id":{"$in":[id1, id0, id2]}}) => [user1, user0, user2]
I don't know if the query syntax supports that (I wouldn't think so), but you can always post-process the results to hash them by lookup id

How to search in SphinxQL by sql_attr_multi field

This is my query to sphinxQL:
SELECT option_id FROM items WHERE cat IN (10,11) GROUP BY option_id LIMIT 100000 OPTION max_matches=100000
cat is sql_attr_multi field, this query not return to me correct result. Anybody knows how to search by fields by this sphinx attribute?
That query looks for items where cat attribute contains either 10 OR 11, is that what you trying to do?
If its not, would help to know what you are trying to query!
I had similar problem.
When I pass array to IN condition for MVA attribute I have no result, however there is several ones in index.
When I debug condition (attribute array(10, 11) in you case) I see that array values is string integer instead.
array(
0 => "10",
1 => "11"
)
For every single value in condition uses quoteArr() function
https://github.com/FoolCode/SphinxQL-Query-Builder/blob/master/src/SphinxQL.php#L518
wich escape value according with https://github.com/FoolCode/SphinxQL-Query-Builder/blob/master/src/Drivers/ConnectionBase.php#L95
The quote function use is_int() PHP internal function:
$a = "1";
var_dump(is_int($a)); // return bool(false)
It mean, thet instead
cat IN (10, 11)
you have
cat IN ("10", "11")
But sphinx can't filter MVA attribute by not integer (string) values no metter IN or OR WHERE notation you use.
[1064] index document : unsupported filter type 'string' on MVA column [ SELECT * FROM `document` WHERE MATCH('(some query)') AND `_category` = '5' LIMIT 0, 10]
You should use strict value type:
foreach ($category as &$item) {
$item = (int)$item;
} unset($item);
I am not sure that it is your incindent. Unfortunately, there isn't enough data to say it for sure in this case.

JPQL: sort queryresult by "best matches" possible?

I have the following question/problem:
I'm using JPQL (JPA 2.0 and eclipselink) and I wanna create a query that gives me the results sorted the following way:
At first the results sorted ascending by the best matches. After that should appear the inferior matches.
My objects are based on a simple class called 'Person' with the attributes:
{String Id,
String forename,
String name}
For example if I'm searching for "Picol" the result should look like:
[{129, Picol, Newman}, {23, Johnny, Picol},{454, Picolori, Newta}, {4774, Picolatus, Larimus}...]
PS: I already thought about using two queries, the first is searching with "equals" and the second with "like", although I'm not quite sure how to connect both queryresults...?
Hope for your help and thanks in advance,
Florian
If, as your question seem to imply, you only have two groups (first group : forename or name equals searched string; second group : forename or name contains searched string), and if all the persons of a given group have the same "match score", then using two queries is indeed a good solution.
First query :
select p from Person p where p.foreName = :param or p.name = :param
Second query :
select p from Person p where (p.foreName like :paramSurroundedWithPercent
or p.name like :paramSurroundedWithPercent)
and p.foreName != :param
and p.name != :param
Execute both queries (each returning a List<Person>), and add all the elements of the second list to the first one (using the addAll() method)