Developer forum

Forum » CMS - Standard features » Sorting by value from IndexSchemaExtender

Sorting by value from IndexSchemaExtender

Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi guys,

I have a project where we have added a couple of extra fields using a Schema extender.

I would like to use them for sorting the product list. Similar to how standard DW is using the OrderCount (which is also a property added using Schema extender).

The fields I am trying to use are both Int32 (just like the OrderCount). However, I cannot convince the sorting to work.

I have tried using the field name directly, I have created separate fields in the index based on the field I am trying to use, and I have tried both Int32 and String without any luck.

Moreover, I have tried sorting by one of the default fields (ProductName, Number) and the sorting works. I have created a new field based on the ProductName or Number (just like the NameForSort is created) but it does not seem to work. All my tests were directly on the feed to exclude any template-related logic. The Query does not have any sorting and the ProductCatalogForViewModel does not have any sorting either.

An apparent trivial task has become a real headache.

What am I doing wrong?

The solution is 9.13.14 and Swift (with very few customizations in front-end). 

Thank you,
Adrian


Replies

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

Can you provide a screendump of your custom field setting in the index? Do you see the expected value when looking at index using LukeNet and/or rendering it using the QueryPublisher?

 

Nuno

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nuno,

I see the expected value when using LukeNet.

This is my setup:

 

For Source, I have tried using my field but also another existing field that works when using directly (like ProductNumber).

I have tried System.Int32 and System.String. No luck.

My query has the default Score selected for sorting:

It works if I use SortBy=Number it does not work if I use SortBy=OrderCountForSort

Adrian

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

Have you tried analyzing the field? I don't know why it would not work. Maybe a bug in Repositories that cannot handle custom index fields for sorting purposes (as odd as that seems)

 

So is your custom field an attempt to work around sorting with OrderCount? If so, all the more reason for this to look like a Bug.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nuno,

I have not tried analyzing the field.

My need is generated by the way the regular OrderCount is calculated.

Weird enough, if you have products with variants, OrderCount on the MasterProduct counts only the sales made for MasterProduct. Which obviously will always be 0.

DW mentioned that they will not change this behavior so we had to come up with our own logic for calculating the OrderCountByVariants and store it on the MasterProduct.

It looks like a bug to me as well but I have not found anything related to this in the list of Bugs or Bug fixes.

Thank you,
Adrian

 

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Hi Adrian,

 

Yep, I see the reason for your need. And, knowing how repositories are ment to work, I understand why it's not standard (and won't be).

 

Going back to the topic, it's odd that it doesn't sort accurately. Seems like a bug, since it should be sorted by OrderCount Descending so that you can get most sold products first. If that does not work, then it's a clear bug in my opinion. From there, we can check custom index fields build with an IndexBuilderExtender.

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Hi Nuno,

I have tested it a bit more and my conclusion is that our data is wrong.

Will revalidate and test again.

Thank you for all your support.

Adrian

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Well... I should have started by asking that :) Good luck

 
Adrian Ursu Dynamicweb Employee
Adrian Ursu
Reply

Actually, you did. And I said that the data is correct. I was wrong :)

Adrian

 
Nuno Aguiar Dynamicweb Employee
Nuno Aguiar
Reply

Oh well... I need more sleep then :)

 

Glad you had it sorted out

 

You must be logged in to post in the forum