Developer forum

Forum » Ecommerce - Standard features » Case insensitive sorting of product using product name

Case insensitive sorting of product using product name

Thaw Htun Lynn
Reply

Hi,

I've tried creating a sorting field using CaseInsesnitiveKeywordAnalyzer but sorting is still case sensitive. Please see the attached screenshot and let me know if i need to change anything in the setup. Thanks.

Regards,

Thaw


Replies

 
Nicolai Pedersen
Reply

Hi Thaw.

You have added an analyzer, but you did not tick the "Analyzed" checkbox for the field...? That means that it will not be analyzed...

PS: Please attach using jpg - they can be shown in the browser.

BR Nicolai

 
Thaw Htun Lynn
Reply

Dear Nicolai,

I tried with various option combinations. If the Analyzed is checked, sorting is all mess up. If I remove the tick on Analyzed, sorting is correct but it is case sensitive, small letters come later.

Regards,

Thaw

 
Nicolai Pedersen
Reply

Hi Thaw

If you just use a normal field and tick analyzed, Dynamicweb uses StandardAnalyzer which is case insensitive already, and that should work.

Could you post examples of what data you have in the field you are sorting, how it looks in UI, your setup of the sort and the result?

BR Nicolai

 
Thaw Htun Lynn
Reply

Dear Nicolai,

I've sent you the URL for our client's UAT environment in the email. Kindly help us to look at the sorting as we have to resolve all the issue by this weekend. Thanks alot.

Best regards,

Thaw

 
Nicolai Pedersen
Reply

Hi Thaw

Could you please explain what you get and what you expect?

Like this:

I get this:

  1. brown
  2. crown
  3. Brown
  4. Crown

But expect this:

  1. brown
  2. Brown
  3. crown
  4. Crown
 
Thaw Htun Lynn
Reply

Hi Nicolai,

If i sort decending, I am getting lower case letters then upper case (z,y,x,...,a, Z,Y, X,...,A) I am expeting the sorting to be case insensitive. (Z,Y,X,..., A)

The follow is some sample data I am getting now.  

1.   xViu Manent E Collection Rsv Merlot 2014 750ml Rx   

2.   xTablas Creek Esprit de Tablas 2012 750ml Redx

3.   de Trafford Straw Wine

4.   Zind Humbrecht Gewurztraminer  

5.   Waipara West Sauvignon

6.   Dom Thierry Navarre Laouzil

In the above 6, I am expecting

1. Zind Humbrecht

2. xViu Manent E Collection Rsv Merlot 2014 750ml Rx   

3. xTablas Creek Esprit de Tablas 2012 750ml Redx

4. Waipara West Sauvignon

5. Dom Thierry Navarre Laouzil

6. de Trafford Straw Wine

 

Best regards,

Thaw

 

 

 

 
Nicolai Pedersen
Reply
This post has been marked as an answer

Hi Thaw

Took a look at this, and I now have an explanation.

You cannot run a sort on a field that is tokenized in the Lucene index - that means you cannot add an analyzer to the field (tick the analyzed checkbox) where as the sort will not work. Another issue is that using an analyzer will split the name of the product into terms (each word in the productname being a term) and sorting on the field makes no sense.

Without an analyzer on the field, the entire name of the product is used for sorting, but since it is not analyzed, it will not be case insensitive giving you the undesired result.

So to solve the issue, I've made a test where the field value is indexed in lowercase if the field is not marked as Analyzed and Stored, but only has the Index checkbox set. See dump #1.

That will give me a possibility of sorting by the entire lowercased product name, see dump #2.

This is a new feature marked as TFS#26315 for 8.9 scheduled for next week.

To solve the issue here and now, you can add a small add-in that will index your value in lowercase, something like this (you might want to check that the productname has a value before lowercasing it):

using Dynamicweb.Indexing;
using System;

namespace Dynamicweb.Examples.CSharp
{
    class IndexBuilderExtenderExample : Indexing.IndexBuilderExtenderBase<Dynamicweb.Ecommerce.Indexing.ProductIndexBuilder>
    {
        public override void ExtendDocument(IndexDocument document)
        {
            if (document.ContainsKey("ProductName"))
            {
                string ProductName = (string)document["ProductName"];
            }
            
            document.Add("ProductNameSortable", ProductName.ToLower(CultureInfo.InvariantCulture));
        }
    }
}

BR Nicolai

Capture.PNG Capture1.PNG
Votes for this answer: 2
 
Thaw Htun Lynn
Reply

Thanks for the solution. I will give it a try today.

 

You must be logged in to post in the forum