Querying structures
Single value The example below shows you how to search the News Item structure based on an Id which is retrieved from the querystring.
# if ($request.getParameter( 'item' )) #set ($query_Id = $request.getParameter('item' )) #set ($query = "+structureName:YOURSTRUCTURENAME +YOURSTRUCTURENAME.Id:$!{query_Id}" ) #end #if($request.getParameter('item'))
#set ($query_Id = $request.getParameter('item'))
#set ($query = "+structureName:YOURSTRUCTURENAME +YOURSTRUCTURENAME.Id:$!{query_Id}")
#end
Multiple values There
will be times when you need to build a query that searches the CMS for
more than one value i.e. News Item region (Africa, Europe etc)
This example gets a list of values from a multiple select field on a form either via the methods get (querystring) or post.
# if ($request.getParameterValues( 'regions' )) #foreach ($regions in $request.getParameterValues('regions' )) #if ($query_regions) #set ($query_regions = "$!{query_regions} YOURSTRUCTURENAME.regions:*${regions}*" ) #else #set ($query_regions = "YOURSTRUCTURENAME.regions:*${regions}*" ) #end #end #if ($query_regions) #set ($query_regions = "+(${query_regions})" ) #end #set($query = "+structureName:YOURSTRUCTURENAME $!{query_regions}" ) #end
Exclude values The example below gets all the items from the YOURSTRUCTURENAME structure but removes all the items which are type:article (- YOURSTRUCTURENAME.type1:Article) notice the minus symbol. This will now display all the blogs, photos and videos.
#set($query = "+structureName:YOURSTRUCTURENAME -YOURSTRUCTURENAME.type1:Article" ) #end
Ordering results by one filter / sort To order a query using just one filter use the following code. (Notice the PressRelease.pubDate desc this is the sorting part):
#set ($cont = $dotcontent.pull( "+structureName:PressRelease" , 0 , "PressRelease.pubDate desc" )) #set ($cont = $dotcontent.pull("+structureName:PressRelease",0,"PressRelease.pubDate desc"))
Ordering results by two sorting filters To order by two values i.e type and then date you need to use a comma to separate the values. See below:
Sort Parameters you can use include: desc, asc and modDate
#set ($cont = $dotcontent.pull( "+structureName:PressRelease" , 0 , "PressRelease.type desc, PressRelease.pubDate desc" )) #set ($cont = $dotcontent.pull("+structureName:PressRelease",0,"PressRelease.type desc, PressRelease.pubDate desc"))
Searching one structure with values from another structure If
you need to search one structure with the values from another structure
then you can use the code below. It is not as straightforward as in SQL
#if ($UtilMethods.isSet($request.getParameter( 'courseTaken' )))
#set($userList = "+UserProfile.userId:(" )
#foreach($course in $dotcontent.pull("+structureName:Courses $!{courseId} " , "0" , "modDate desc" ))
#set($userList = "$userList $course.userUid or" ) #end #set($userList = "$userList )" ) #set($query = "+structureName:UserProfile +UserProfile.userType:*Alumni* $!{userList} $!{location}" ) $query #end
Other query examples If you need to search for several categories then you need to use the examples shown below:
Query to pull all Blogs with category: Investing OR category: Conferences selected
+structureName:Blog +(categories:investing categories:conferences) +structureName:Blog +(categories:investing categories:conferences)
Query to pull all Blogs with category: Investing AND category: Conferences selected
+structureName:Blog +categories:investing +categories:conferences +structureName:Blog +categories:investing +categories:conferences
Query to pull all Blogs with category: Investing AND NOT category: Conferences selected
+structureName:Blog +categories:investing -categories:conferences +structureName:Blog +categories:investing -categories:conferences
Query to pull all Blogs with category: Investing AND (category: Conferences OR category: releaseDates) selected
+structureName:Blog +categories:investing +(categories:conferences categories:categories:releaseDates) +structureName:Blog +categories:investing +(categories:conferences categories:categories:releaseDates)
Query
to pull all Blogs with (category: Conferences AND category:Banking) OR
(category: Investing AND category: releaseDates) selected
+structureName:Blog +( (+categories:conferences +categories:banking) (+categories:investing +categories:releaseDates) ) +structureName:Blog +( (+categories:conferences +categories:banking) (+categories:investing +categories:releaseDates) )
Please enable JavaScript to view the comments powered by Disqus.
comments powered by