Category App

paul carter asked on November 6, 2019 15:04

I have a dropdown smart filter, and wanting to list some root and subcategories from the category app to use as a filtering choice in my smart search filter.

ie Categories News Type Membership News Other News Event Type

Based on the categories i Require in My list the drop down would produce something like:

Membership News Event Type

which then provide a selection list for my filter, or is it just as easy to place the details in the values dialog such as:

  • Membership News
  • Event Type

And would this work ?

Recent Answers


paul carter answered on November 6, 2019 15:05

Sorry the formatting of my example should be vertical

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on November 6, 2019 18:33

Hi Paul,

I haven't tried this, but I would think you could create a query that provides the list of categories you want to display in the Smart Search Filter, including the columns required by the web part -- something like this:

SELECT
    IndexName = 'paulsindex',
    CategoryName,
    CategoryDisplayName
FROM
    CMS_Category
WHERE
    CategorySiteID IS NULL -- NULL if the category is global; SiteID if the category is a site category
AND
    CategoryParentID IS NULL -- NULL if the category is root category, or CategoryID if the parent category

After creating the query, it can be selected in the web part's "Query name" property.

Mike

0 votesVote for this answer Mark as a Correct answer

paul carter answered on November 7, 2019 13:11 (last edited on December 10, 2019 02:31)

Hi Can you elobate a bit more on how this sits in a smart filter web part, still a bit new at this. This was my original Query which works on a general level

SELECT 'DocumentCategoryIDs','-1', '(all)' AS CategoryDisplayName UNION SELECT '+DocumentCategoryIDs', CategoryID, CategoryDisplayName FROM CMS_Category WHERE ##WHERE## ORDER BY ##ORDERBY##

Where Condition

((CategorySiteID IS NULL) OR (CategorySiteID = {% CurrentSite.SiteID |(identity)GlobalAdministrator%}))

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on November 8, 2019 19:23 (last edited on December 10, 2019 02:31)

Hi Paul,

The first column in the query needs to be the index name. To find that, look up the index's Code Name in the Smart Search module. Without trying it myself, I think the SQL query would look more like this:

SELECT 
    'paulsindexname',
    '-1',
    '(all)' AS CategoryDisplayName
UNION SELECT
    'paulsindexname',
    CategoryID, 
    CategoryDisplayName 
FROM
    CMS_Category
WHERE ##WHERE## 
ORDER BY ##ORDERBY##

Also, I'm not sure you want to filter by CategoryUserID. How about just this for the Where Condition?

((CategorySiteID IS NULL) OR (CategorySiteID = {% CurrentSite.SiteID |(identity)GlobalAdministrator%}))

Mike

0 votesVote for this answer Mark as a Correct answer

paul carter answered on November 11, 2019 10:14

I understand what you are saying, and have been playing with some SQL. Having spoken to my project lead they have specified they want a list of specific categories and their children. Im finding it difficult to understand how i am able to display these specific categories in my filter list rather than all of them.

0 votesVote for this answer Mark as a Correct answer

paul carter answered on November 11, 2019 10:21

Actually on further reflection, i have realised that the categories i require all sit under a root category called resources. I assume this would make it easier to list knowing this root ?, if so how would i display that ?

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on November 11, 2019 19:31

Hi Paul,

How to filter by a parent category is in the first answer. The where condition should contain:

CategoryParentID = [the CategoryID of your Resources category]

Mike

0 votesVote for this answer Mark as a Correct answer

paul carter answered on November 12, 2019 11:53

Hi Guys, I actually managed to get my filter displaying single root categories, and only sub child categories, using the following. Seems to work great. Not sure how elegant it is, but it works.

SELECT 'DocumentCategoryIDs','-1', '(all)' AS CategoryNamePath UNION SELECT '+DocumentCategoryIDs', CategoryID, CategoryDisplayName FROM CMS_Category WHERE ##WHERE## ORDER BY ##ORDERBY## Where Clause : CategoryLevel > 1 AND CategoryParentID IN (21,31,34,38,42,50,54,57,60)

0 votesVote for this answer Mark as a Correct answer

Mike Wills answered on November 12, 2019 17:46

Alright, thanks fur the update.

0 votesVote for this answer Mark as a Correct answer

   Please, sign in to be able to submit a new answer.