Developer forum

Forum » Development » RE: Problems sorting using repositories inde

RE: Problems sorting using repositories inde

Rasmus Andersen
Reply

Hi DW, 

I am implementing some simple sorting using repositories:

  • Price (works)
  • Name (Does not work)

The sorting is called from code: 

var sortList = new List<SortInfo>();
sortList.Add(new SortInfo
{
    Field = "Name",
    SortDirection = SortDirection.Descending
});

Only one item is in the list and later inserted into the QueryService Search method. 

It looks like an error sorting strings as the results seems random, but sorting on price works just as expected. 

What could cause this issue or could it be an issue in DW?
 


Replies

 
Nicolai Høeg Pedersen
Reply

Hi Rasmus

Can we see some more of your code - the context in which this happens?

 
Jeppe Eriksson Agger Dynamicweb Employee
Jeppe Eriksson Agger
Reply
This post has been marked as an answer

Hi Rasmus,

The sort works, though probably not as you expect. The issue is that Lucene uses ordinal sort, which means that there's a difference between uppercase and lowercase letters. The solution is to sort on a field that has only one casing or is analyzed without differentiation between uppercase and lowercase. This becomes even trickier when using an analyzed field as it might strip parts that does not match ruleset of the tokenizer.

There are two ways to solve the issue, though one solution requires Dynamicweb 8.7 or later.

The easiest (and the one the requires 8.7+) is to create a new Field Type in the index definition and select the CaseInsensitiveKeywordAnalyser. Then create a new field that uses the source you need (probably ProductName going by your post) and select your custom Field Type under Type for the field.

The second solution requires you to implement an IIndexBuilderExtender<ProductIndexBuilder> that copies the value of the field in question into a new field that is lowercase. You can see how to create one here: http://developer.dynamicweb.com/forum/cms-standard-features/new-index-sort-product-order-in-product-group.aspx?PID=48

I would only recommend the second solution if you're forced to use Dynamicweb 8.6.1.X. If you're using Dynamicweb 8.7 or later, then the first solution is by far the best.

- Jeppe

 

Votes for this answer: 1
 
Nuno Aguiar
Reply
This post has been marked as an answer

Hi Rasmus,

 

I had the same issue. The field is indexed (for better free text searching), hence not sortable.

 

Check this: http://developer.dynamicweb.com/forum.aspx?PID=48&ThreadID=42556

 

Best Regards,

Nuno Aguiar

Votes for this answer: 1
 
Rasmus Andersen
Reply

Thank you guys,

I appereaciate all your answers and will try to upgrade tomorrow :)

 

You must be logged in to post in the forum