Filter blogs based on category

Enonic version: 2.8.2
OS: YourOS
xpVersion = 7.10.0

In my project, i have created a blog content type

 <item-set name="blog_fields">
<label>Blog Details</label>
<items>
<input name="title" type="TextLine" >
  <label>Title</label>
</input>
<input name="description" type="TextLine" >
  <label>Description</label>
</input>
 <input name="main-image" type="ImageSelector" >
  <label>Main Image</label>
</input>
<input name="categoryselector" type="ContentSelector">
  <label>Category Selector</label>
  <occurrences minimum="0" maximum="1"/>
  <config>
    <allowPath>${site}/blog-categories/</allowPath>  
    <treeMode>true</treeMode>   
    <hideToggleIcon>true</hideToggleIcon>  
  </config>
</input>
 <input name="created_on" type="DateTime">
  <label>Created on</label>
</input>
 <input name="htmlarea" type="HtmlArea">
  <label>Html Content for Blog</label>
</input>
</items>
 </item-set>

I am using guillotine to fetch data with query and my guillotine version is 6.0.6.
My query is
`query($path:ID!, $first: Int!, $offset: Int!){
guillotine {

query(key:$path, first:$first, offset:$offset, filters: {hasValue: {field: "data.blog_fields.title", stringValues: ["Blog 2", "Blog 3"]}}) {
  displayName
  _id
  hasChildren
  _name
  __typename
 ... on myproject_Blog{
  data{
    blog_fields {
      title
      description
      created_on
      read_time
      main_image {
          ... on media_Image {
            imageUrl(type: absolute, scale: "width(800)")
            _name
          }
        }
        categoryselector {
          displayName
          _name
          _id
          ... on myproject_Blogcategory{
            data {
              category_name
            }
          }
        } 
    }
    
   
  }
}
}

}
}`

I am able to filter data when i given this value ( field: “data.blog_fields.title” ) then filter is working but i want to filter based on categoryselector field, when i given this value ( field: “data.blog_fields.categoryselector.data.category_name” ) then it is not working.

So how can i achieve this

Hi Ajay.

You cannot search for items based on values in related content, you may only search indexed properties for each content. Even if you can extract related data, you can only search for the ID of the related categories in the “categoryselector” field.

Via the data toolbox app, you can see what information is indexed per content item/property

BTW: consider using the name “category” rather than “categoryselector” for this field, as this would be a more precise name for what you actually store.

Thanks, I have changed “categoryselector” to “category”, i am not able to get information about index per content item/property in data toolbox app.

Is there any other way to achieve this functionality as i want to show blogs based on their category

You don’t really have to dive into Data toolbox for this, simply look at the JSON output of your content, you will see the data that will be indexed.

I.e. your category JSON might look like this:
“category”: “f4386113-1bee-41c3-9fd9-dd6c04e903bb”

or “category”: [“id1”,“id2”,“id3”] (where each value represents the id of the target content).

So, in order to search, you must now pass the ID of the selected categories to your query.