5

I have a working installation of Sitecore 7 + Glass Mapper 3 which I am looking to optimize.

An example of my code is:

[SitecoreQuery(".//*[@@templateid = '{011EC776-D9F3-4D73-8D8D-E454417E7574}']", 
                                                               IsRelative = true)]
IEnumerable<ItineraryLine> Itinerary { get; set; }

I was hoping to use FastQuery but I get the error:

End of string expected at position 4

I gave the following solution a try this involves slotting in to the getLookupSourceItems pipeline - but I don't think this is the right pipeline as it doesn't trigger in debug.

Is there another pipeline (if at all) that Glass uses in this scenario? Is there a different way I can solve my goal of speeding this up?

If I wasn't using attributes but extension methods I could do this manually and use *[@@id=''] to set the root node, but I was hoping to avoid this if possible.

Wai Ha Lee
  • 8,598
  • 83
  • 57
  • 92
Steve McGill
  • 501
  • 2
  • 15

1 Answers1

7

When using the IsRelative setting to true GMS pushes the query throught Axes SelectItem. Sitecore does not allow fast query for Axes selects, e.g.:

Item.Axes.SelectItems("fast:./*");

See documentation here page 3:

http://www.iosh.co.uk/~/media/using%20sitecore%20fast%20query001.ashx

However GMS being awesome allows us to solve this another way, you can put placeholders in your query that GMS will expand. Removing the IsRelative property and using the {path} placeholder allows the same result:

[SitecoreQuery("fast:{path}//*[@@templateid = '{011EC776-D9F3-4D73-8D8D-E454417E7574}']")]
IEnumerable<ItineraryLine> Itinerary { get; set; }

The path placeholder will be expanded to the full path of the current item being mapped.

Michael Edwards
  • 6,308
  • 6
  • 44
  • 75
  • I'm still getting the error "End of string expected at position 32" - I can't seem to find out what {path} is being replaced with to debug this further. I also copy/pasted what you wrote just to make sure. Thanks so far! – Steve McGill Jan 26 '14 at 19:37
  • I just copy and pasted it again and it worked fine for me. Can you paste your code into here again? – Michael Edwards Jan 26 '14 at 22:42
  • Could it be the path has items with keyword names in it, which Glass isn't handling? i.e 'and'. I know that database.SelectItems(query) will struggle with paths unless they've been escaped in the query. – Sean Holmesby Jan 28 '14 at 15:59
  • 2
    I had the same problem and found that I can use {escapedPath} instead of {path} – Kjaneb Sep 04 '14 at 05:28