How to use AND , OR , () clauses in Solr query? - solr

I need a Solr query with AND, (), OR, clauses, something like this
search +TYPE:"ecmcndgostst:nd_gost_standards" +#ecmcnddoc\:doc_kind_cp_ecmcdict_value:"gost_gost" AND (+#ecmcnddoc\:biblio_fond:"standard" OR +#ecmcnddoc\:biblio_fond:"regulations")
(it's just an example this query doesn't work).
It is an attempt to re-write in Solr the following CMIS query:
SELECT p.cmis:objectId FROM ecmcnddoc:common_attr_aspect AS d JOIN ecmcnddoc:biblio_attr_aspect AS p ON d.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:reg_attr_aspect AS s ON s.cmis:objectId = p.cmis:objectId JOIN ecmcnddoc:spec_attr_aspect AS asp ON asp.cmis:objectId = p.cmis:objectId WHERE p.cmis:objectTypeId='D:ecmcndgostst:nd_gost_standards' AND d.ecmcnddoc:doc_kind_cp_ecmcdict_value='gost_gost' AND (p.ecmcnddoc:biblio_fond='standard' OR p.ecmcnddoc:biblio_fond='regulations')
Could you help me with Solr ?

Related

MS Access query making sure Higher retails match

I'm trying to build a query in MS Access and having an issue figuring out the best way to build it. What I'm trying to do is is make sure all the Higher retails match within a set of matching pack numbers. For example:
PackNum Prefix Retail
6451618 DF 37.99
6451618 SK 37.99
6451618 VJ 34.99
6451618 SG 37.99
One of the group is off and I want the query to show it.
I was attempting to use something like this to have check but I'm not getting the results I'm looking for
IIf([dbo_PIC704Current]![PackNum]=[dbo_PIC704Current]![PackNum]
And [dbo_PIC704Current]![Ret2]<>[dbo_PIC704Current]![Ret2],True,False)
Any help or push in the right direction would be greatly appreciated!
-Deke
SELECT dbo_pic704current.packnum
, Min(dbo_pic704current.Ret2) AS LowRet2
, Max(dbo_pic704current.Ret2) AS HighRet2
, dbo_CatalogInfo.MediaId
, dbo_pic704current.DiscountReasonCode
, dbo_CatalogInfo.Brand
FROM dbo_pic704current INNER JOIN dbo_CatalogInfo ON (dbo_pic704current.year =
dbo_CatalogInfo.mailyear) AND (dbo_pic704current.catid = dbo_CatalogInfo.catalog)
WHERE (((dbo_CatalogInfo.MediaId)='CAT Catalog'))
GROUP BY dbo_pic704current.packnum, dbo_CatalogInfo.MediaId,
dbo_pic704current.DiscountReasonCode, dbo_CatalogInfo.Brand, dbo_pic704current.Year
HAVING (((Min(dbo_pic704current.Ret2))<>Max([Ret2])))
ORDER BY dbo_pic704current.packnum;
Your existing solution using aggregation is likely to yield better performance, but to offer an alternative, here is an example using a correlated subquery:
select
pc.packnum, pc.ret2, ci.mediaid, pc.discountreasoncode, ci.brand
from
dbo_pic704current pc inner join dbo_cataloginfo ci on
pc.year = ci.mailyear and pc.catid = ci.catalog
where
ci.mediaid = 'cat catalog' and exists
(select 1 from dbo_pic704current t where t.packnum = pc.packnum and t.ret2 > pc.ret2)
order by
pc.packnum

SQL Server - Getting XML from result set within one tag

I am trying without much success to build a XML out of my result set.
My result set should look like this :
<CSVRoot>
<CsvColumn>MDCY_Code</CsvColumn>
<CsvColumn>MDCY_Description</CsvColumn>
</CSVRoot>
This is what my query returns :
<CSVRoot>
<CSVHeader>
<CsvColumn>MDCY_Code</CsvColumn>
</CSVHeader>
<CSVHeader>
<CsvColumn>MDCY_Description</CsvColumn>
</CSVHeader>
</CSVRoot>
I know that I can use flowr on this formed XML and remake the XML, but that's additional processing. Is there any way to do this without further processing ( such as using a flowr to form a new XML ) in one query?
This is what I've used:
select
utma.CsvColumn as [ColumnName]
from
Methods m
inner join
UITestMap utm on m.UITestMapID = utm.ID
inner join
SubMethods sm on m.Id = sm.HeaderID
inner join
UITestMapActions utma on sm.UITestMapActionID = utma.ID
for xml path('CSVHeader'),root('CSVRoot')
Edit 2 :
This isn't working, I get the same output.Utma has one column that I need in my query and that is CSVColumn.
Edit 3:
Now I'm getting this :
<CsvHeader>
<ColumnName>MDCY_Cod</ColumnName>
<ColumnName>MDCY_Descriere</ColumnName>
</CsvHeader>
Which is the correct answer.
I wasn't sure how I wanted to process the result sets, actually I will need to use flowr to create a new xml out of this output. ( which is what I needed in the first place)
Try this:
select
utma.CsvColumn
from
Methods m
for xml path(''),root('CSVRoot')

Doctrine Query Builder not working with UPDATE and INNER JOIN

In my repository I have this query:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->update('MyBundle:Entity1', 'e1')
->join('e1.Entity2', 'e2')
->set('e1.visibile', '1')
->andWhere('e2.id = :id')->setParameter("id", 123)
;
throw this error
[Semantical Error] line 0, col 66 near 'e2.id = :id': Error: 'e2' is not defined
I have checked the relation and it is right.
Is there any issue using join in query update?
You can not use join on update and delete queries. You have to use subqueries.
Joins are not supported on update and delete queries because it is not
supported on all dbms. It won't be implemented in Doctrine 1 or
Doctrine 2. You can however get the same affect by using subqueries.
http://www.doctrine-project.org/jira/browse/DC-646
If you are using MySQL, using subqueries will not work. You will have then to use 2 queries.
In MySQL, you cannot modify a table and select from the same table in
a subquery
http://dev.mysql.com/doc/refman/5.0/en/subqueries.html
Doctrine DQL does not support join in update.
Try doing the following :
$qb = $this->getEntityManager()->createQueryBuilder();
$qb
->update('MyBundle:Entity1', 'e1')
->set('e1.visibile', '1')
->where('e1.Entity2 = :id')
->setParameter("id", 123)
;
You can set the id, as long as it is the primary key, of the linked entity directly as if it was the entity, Doctrine will map it.
I'm doing the exact same thing in my queries and it works.
try using a subquery instead Join will not work in DQL while you re doing an update:
LEFT JOIN, or JOINs in particular are only supported in UPDATE
statements of MySQL. DQL abstracts a subset of common ansi sql, so
this is not possible. Try with a subselect:
$qb = $this->getEntityManager()->createQueryBuilder();
$qb ->update('MyBundle:Entity1', 'e')
->set('e.visibile', '1')
->where('e.id IN (SELECT e1.id FROM Entity1 e1 INNER JOIN e2.Entity2 e2 WHERE e2 = :id')
->setParameter("id", 123);
Very old question, but do not contain an answer in full query builder.
So yes, the following query is not possible to sync fields of two tables:
$this->createQueryBuilder('v')
->update()
->join(Pegass::class, 'p', Join::WITH, 'v.identifier = p.identifier')
->set('v.enabled', 'p.enabled')
->where('p.type = :type')
->setParameter('type', Pegass::TYPE_VOLUNTEER)
->andWhere('v.enabled <> p.enabled');
The generated query do not contain the relation because of its lack of support in all dbms as explained above. They also tell you to use subqueries instead.
So that's how I did the equivalent (even if using 2 queries and is less performant...):
foreach ([false, true] as $enabled) {
$qb = $this->createQueryBuilder('v');
$sub = $this->_em->createQueryBuilder()
->select('p.identifier')
->from(Pegass::class, 'p')
->where('p.type = :type')
->andWhere('p.enabled = :enabled');
$qb
->setParameter('type', Pegass::TYPE_VOLUNTEER)
->setParameter('enabled', $enabled);
$qb
->update()
->set('v.enabled', $enabled)
->where($qb->expr()->in('v.identifier', $sub->getDQL()))
->getQuery()
->execute();
}

Convert this SQL Query to LINQ Query

I need to convert this SQL Query to LINQ Query, also I need to expose the SQL Select properties:
SELECT Problem.ProblemID, ProblemFactory.ObjectiveID, Objective.Name, ProblemFactory.Time, ProblemType.ProblemTypeName, ProblemFactory.OperationID,
ProblemFactory.Range1ID, ProblemFactory.Range2ID, ProblemFactory.Range3ID, ProblemFactory.Range4ID,
ProblemFactory.MissingNumber
FROM Problem INNER JOIN ProblemFactory ON Problem.ProblemFactoryID = ProblemFactory.ProblemFactoryID
INNER JOIN ProblemType ON ProblemFactory.ProblemTypeID = ProblemType.ProblemTypeID
INNER JOIN Objective ON Objective.ObjectiveID = ProblemFactory.ObjectiveID
UPDATE 1:
This is what I have:
var query = from problem in dc.Problem2s
from factory
in dc.ProblemFactories
.Where(v => v.ProblemFactoryID == problem.ProblemFactoryID)
.DefaultIfEmpty()
from ...
And I'm using this example: What is the syntax for an inner join in LINQ to SQL?
Something like this?
var query =
from p in ctx.Problem
join pf in ctx.ProblemFactory on p.ProblemFactoryID equals pf.ProblemFactoryID
join pt in ctx.ProblemType on pf.ProblemTypeID equals pt.ProblemTypeID
join o in ctx.Objective on pf.ObjectiveID equals o.ObjectiveID
select new
{
p.ProblemID,
pf.ObjectiveID,
o.Name,
pf.Time,
pt.ProblemTypeName,
pf.OperationID,
pf.Range1ID,
pf.Range2ID,
pf.Range3ID,
pf.Range4ID,
pf.MissingNumber,
};
But what do you mean by the "SQL Select properties"?
One of the benefits of an ORM like Linq-to-SQL is that we don't have to flatten our data to retrieve it from the database. If you map your objects in the designer (i.e. if you have their relationships mapped), you should be able to retrieve just the Problems and then get their associated properties as required...
var problems = from problem in dc.Problem2s select problem;
foreach (var problem in problems)
{
// you can work with the problem, its objective, and its problem type.
problem.DoThings();
var objective = problem.Objective;
var type = problem.ProblemType;
}
Thus you retain a logical data structure in your data layer, rather than anonymous types that can't easily be passed around.

Choosing SQL join types for Entity Framework 4

I have a query for example:
var personList = context.People;
People is a view that has 2 joins on it and about 2500 rows and takes ~10 seconds to execute.
Looking at the Estimated Execution plan tells me that it is using a nested loop.
Now if i do this:
var personList = context.People.Where(r => r.Surname.Length > -1);
Execution time is under a second and the execution plan is using a Hash Join.
Adding "OPTION (HASH JOIN)" to the generated SQL has the desired effect of increasing performance.
So my question is ...
How can i get the query to use a Hash Join? It can't be added to the view (I tried, it errors).
Is there an option in EF4 that will force this? Or will i have to put it in a stored procedure?
RE: View
SELECT dbo.DecisionResults.ID, dbo.DecisionResults.UserID, dbo.DecisionResults.HasAgreed, dbo.DecisionResults.Comment,
dbo.DecisionResults.DateResponded, Person_1.Forename, Person_1.Surname, Site_1.Name, ISNULL(dbo.DecisionResults.StaffID, - 999)
AS StaffID
FROM dbo.DecisionResults INNER JOIN
Server2.DB2.dbo.Person AS Person_1 ON Person_1.StaffID = dbo.DecisionResults.StaffID INNER JOIN
Server2.DB2.dbo.Site AS Site_1 ON Person_1.SiteID = Site_1.SiteID
ORDER BY Person_1.Surname
If i add OPTION(HASH JOIN) to the end it will error with :
'Query hints' cannot be used in this query type.
But running that script as a query works fine.

Resources