3

In my template, I have a field called Category which is a type of DropLink and not MultiList. When I tried to find it in SOLR, I got this field as below.

"category_sm":["{951063A6-0BBA-484F-8CAB-A7C11AF977BA}"]

When I tried to query this field like

categoryQuery = categoryQuery.And(i => i.CategoryId.Contains(Guid.Parse(payload.CategoryId)));

Where the CategoryId field is defined in the Model like.

[IndexField("category_sm")]
public List<Guid> CategoryId { get; set; }

I got no result. When I check the log, I found that category id is being parsed as

?q=(_template:(f250acc7e16e4f6cb7b8a2e6f41a6bf4) AND category_sm:(05414a8228ea40b18a4d86fcbdbf4a97))&start=0&rows=1000000&fl=*,score&fq=_indexname:(sitecore_master_index)

instead of

?q=(_template:(f250acc7e16e4f6cb7b8a2e6f41a6bf4) AND category_sm:{951063A6-0BBA-484F-8CAB-A7C11AF977BA})&start=0&rows=1000000&fl=*,score&fq=_indexname:(sitecore_master_index)

Sitecore Version: 9.3 SOLR: 8.1.1

1
  • What version of Sitecore
    – Chris Auer
    Mar 1, 2020 at 9:48

2 Answers 2

1

You index field should be

[IndexField("category")]
public List<string> CategoryId { get; set; }

And your code

categoryQuery = categoryQuery.And(i => i.CategoryId.Contains(IdHelper.NormalizeGuid(payload.CategoryId)))

Or like Sitecore does the Paths field

[IndexField("category")]
public List<ID> CategoryId { get; set; }

categoryQuery = categoryQuery.And(i => i.CategoryId.Contains(payload.CategoryId))
3
  • Thanks @chris-auer, i tried your solution but now i got this in query log. q=(_template:(f250acc7e16e4f6cb7b8a2e6f41a6bf4) AND category_txm:(05414A8228EA40B18A4D86FCBDBF4A97))&start=0&rows=1000000&fl=*,score&fq=_indexname:(sitecore_master_index)&wt=xml&sort=__smallcreateddate_tdt desc Mar 1, 2020 at 4:28
  • Interesting. I added another example using IDs. Similar to how Sitecore does the Paths object.
    – Chris Auer
    Mar 1, 2020 at 9:48
  • With List<ID>, I got this error message in search log. [undefined field category] - Query attempted: [(_template:(f250acc7e16e4f6cb7b8a2e6f41a6bf4) AND category:(05414a8228ea40b18a4d86fcbdbf4a97))]. After this i also tried to changed the index field attribute like [IndexField("category")] but got the same error message. Mar 1, 2020 at 14:55
1

Somehow I managed to solve the issue. Below are the steps I had taken.

  1. I used exact same code that I have mentioned in my question. Category field attribute In my case, it is category_sm
  2. I used List<Guid> When I used List<ID> i got [undefined field category] error
  3. Rebuild the full index of particular database.

When I rebuilt the indexes, I got to know that, the category id value is now

"category_sm":["951063a60bba484f8caba7c11af977ba"],

instead of eariler as i mentioned in question.

"category_sm":["{951063A6-0BBA-484F-8CAB-A7C11AF977BA}"]

I think this was the major issue that SOLR storing the id with {} and -. Which is not usual. It should store id value as ["951063a60bba484f8caba7c11af977ba"] without {} and -

This is my assumption, and still would like to know, why it has happened and what is the root cause of DropLink value is being captured as formatted GUID instead of a plane id.

My final code is like

[IndexField("category_sm")]
public List<Guid> CategoryId { get; set; }

and this is the query

categoryQuery = categoryQuery.Or(i => i.CategoryId.Contains(Guid.Parse(catId)))

Thanks a lot @chris-auer for his guidance.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.