Solr, select where in select - apache

I'm trying to do a query with a select in another.
I would like to do something like:
select?q=*:* AND id_user=5&fl=id_other
select?q=test AND -id(the result of the other select)&fl=id
So:
select?q=test AND -id(select?q=* AND id_user=5&fl=id_other)&fl=id
Is it possible? Or I have to do two separates selects?
$ids = select?q=*:* AND id_user=5&fl=id_other
$result = select?q=test AND -id(implode(' AND ', $ids))&fl=id
Thanks!

There is a nested query support in Solr. You can _query_ parameter to embed query into another. Check this tutorial for more information.

Related

Codeigniter database queries with multiple LIKE parameters

How can I perform a query with multiple LIKE parameters?
For example, I have this string to search through:
"I like searching very much"
This is the code I currently use:
$searTerm = "like"
$this->db->or_like('list.description', $SearchTerm,'both');
But i want to search with 2 or 3 parameters. like this:
$searTerm = "like"
$searTerm1 = "much"
How can i perform this to get the same result?
You can simply repeat the like parameters on the active record. In your example you would do something like this:
$this->db->or_like('list.description', $searchTerm1);
$this->db->or_like('list.description', $searchTerm2);
$this->db->or_like('list.description', $searchTerm3);
...
This will just join each or_like with an AND in the WHERE clause.
Firstly, you need to define the array with like variables then, its very important to put the or_like statement above the where clause in order to make multiple 'OR' statements for like 'AND' the where clause.
Here is example:
$this->db->or_like(array('column_name1' => $k, 'column_name2' => $k))
$this->db->where($whereColumn, $whereValue)
You can use like group
$this->db->group_start()->like('column_name1', $value)
->or_group_start()
->like('column_name2', $value)
->group_end()
->group_end();

MongoDB equivalent for select "of" select?

I would like to know what is the best way to translate a SQL query like:
select * from table where id in(
Select id from table where field1="titi" )
For the moment I get a two steps query:
CALLMATCH = db.appels.find({"EVENTDATA": /.*442251434*./} , {CALLID: 1});
db.appels.find({"CALLID": {$in: CALLMATCH} } );
Is there a better way to perform this kind of query?
And a second question is how to display the result in a file? (since it is not very pratical to check the result through the cmd console...)
In advance thank you for your feedback!
Regards,
Fabien.
Mongo does not support joins so you have to do two queries.
In order to save the result set to a file you can simply redirect the output to a file such as this:
mongo [script] > output_file.txt
where script is a file with your queries ending with .js

Using WHERE clause to only retrieve results where array field has only ONE element inside

I have a table with various arrays within it like this:
{10574664,10574665,10574679,10574724}
{8616204,10574643,10574644,10574645,10574651,10574688,10574690,10574696,10574708}
{8616208}
{9830397}
{8616203}
{8616204,10574643,10574644,10574645,10574651,10574688,10574690,10574696,10574708}
{8616204,10574643,10574644,10574645,10574651,10574688,10574690,10574696,10574708}
{8616208}
{10574680}
{8616203}
Is there a way to only pull back the records where there is only one element in the array.
The results would look like this:
{8616208}
{9830397}
{8616203}
{8616208}
{10574680}
{8616203}
My query would look something like this
Select * from attr_lookup where target_tcode = help with query here
Use array_length():
SELECT *
FROM attr_lookup
WHERE array_length(target_tcode, 1) = 1;

Doctrine, escape variable field name in DQL

I have a DQL query like:
$em->createQuery("
SELECT r
FROM WeAdminBundle:FamilyRelation r
WHERE r.col like :query
")
Now I want to change "col" depending on various parameters. How can i achieve this with DQL since the normal setParameter doesn't work here.
You can use setParameter with DQL, as many examples are provided but for LIKE clauses, make sure the variable is wrapped in %.
$em->createQuery("
SELECT r
FROM WeAdminBundle:FamilyRelation r
WHERE r.col like :query
")->setParameters(array(
'query' => '%'.$foo.'%'
))
In short: you can't the way you want it.
To do it you'd need something like $dql->setColumn(array('variable_column' => 'some_column_name')) just as the bindColumn method from PDO, but there's no equivalent method (bindColum or setcolumn) in Doctrine.
For use of different parameter instead of col please see below example:
$var = "r.col";
Here you can change based on condition.
$em->createQuery("
SELECT r
FROM WeAdminBundle:FamilyRelation r
WHERE ".$var." like :query
")
please have a look it.

How to put this Query into Linq (C#)?

I'm able to do:
var codeStation = from Code in ent.Role
where Code.Code.StartsWith("S_")
select Code;
(ent: being my Entity for my Database)
That gives me :
S_ANC
S_ATL
S_BNA
S_BOS
S_BRU
S_CLT
.....
S_YXE
S_YXY
S_YYC
S_YYG
S_YYT
S_YYZ
How can I accomplish the equivalent of the following SQL query?
SELECT Substring(Codes,3,6)
FROM Role
WHERE Codes LIKE 'S%'
Thanks!
var codeStation = from Code in ent.Role
where Code.Code.StartsWith("S_")
select RoleName.Substring(3,6);
Your LINQ query can select any legal C# expression you want, including method calls on the field names. So, you can do something like this:
var codeStation = from Code in ent.Role
where Code.Code.StartsWith("S_")
select Code.RoleName.SubString(3,6);