In sitecore get all child and grand child items using fast query
Asked Answered
H

4

5

In sitecore i want to get all child and grand child which inherited form "Industrial Product template .

Below are the fast query , but its giving error Error : End of string expected at position 5.

Fast query:

_masterdb.SelectItems("query:/sitecore/content/Product Catalog/Industrial/Products/*[@@templatename='Industrial Product']")

Hydantoin answered 27/2, 2014 at 4:10 Comment(2)
Please note that "fast" doesn't nescessarely mean fast. You probably want to look into indexing to solve what you need.Advert
Or since you are using Sitecore 7, use ContentSearchManager and LINQ to Sitecore if you don't want to create your own search indexesSirreverence
T
7

Your query is not a fast query, if you use the following query, it worked for me:

_masterdb.SelectItems("fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templatename='Industrial Product']");

There are two changes in this query:

  • Replace the keyword query at the beginning to fast. This means that it is not a "normal" Sitecore Query, it becomes a Sitecore Fast Query. Please read this guide for more informations about using fast queries.
  • Before selecting your items with *[@@templatename='Industrial Product'], I've added a double slash //. This means, that it searched recursive for all items with your template. With your query you only search for direct child items.

Also, I would recommend you to using the keyword @@templateid instead of @@templatename, as sitecore climber said it's faster and it's also no problem if you rename the template. So your query could look like this at the end:

fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templateid='{76036F5E-CBCE-46D1-AF0A-4143F9B557AA}']

Note: This does not only select your children and grand children. This does recursively gives you all items with this template.

Tremolo answered 27/2, 2014 at 9:10 Comment(2)
Thanks kevin, your answer is comprehensive and pre-empted my question re what's the difference between a normal query and a fast query.Micrometeorite
@Micrometeorite in most cases fast query is faster, it's a different approach how Sitecore queries the database. A small Google gives me e.g. these links: bugdebugzone.com/2014/08/… and firebreaksice.com/options-for-querying-items-from-sitecoreCondillac
M
6

This is not fast query, you are using normal query . Please use something like :

Sitecore.Data.Items.Item[] items = 
 database.SelectItems("fast:/sitecore/content/Product Catalog/Industrial/Products//*[@@templateid='yourTemplateId']"); 

Also please use @@templateid not @@templatename, I made some tests and it's faster using @@templateid.

Also have a look here about using FastQuery.

Mobley answered 27/2, 2014 at 4:56 Comment(0)
S
2

Please use below query

_masterdb.SelectItems("query:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='Industrial Product']")

Scleroma answered 11/6, 2014 at 13:4 Comment(0)
R
0

Try this

_masterdb.SelectItems("fast:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='Industrial Product']")

or

_masterdb.SelectItems("fast:/sitecore/content/#Product Catalog#/Industrial/Products//*[@@templatename='industrial product']")

In some cases, you may need to escape names that contain spaces, such as @#Updated by#.

Refresher answered 27/2, 2014 at 11:8 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.