Problems whith sorting strings whith simular beginings.

Vote:
 

I am trying to sort a result but it seams to only apply to x first charaters I got a SearchTitle where many pages begins whith the same 100-200 chars, when i try to sort on those SearchTitles they does not get sorted. Anyone know something about this?

#176529
Mar 20, 2017 16:24
Vote:
 

Hi Niklas can you give some example code or results?

#176734
Mar 24, 2017 10:31
Vote:
 

Results (the orange marked ar not ordered):

  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång biologi/kemiProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång engelskaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång historiaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång idrott och hälsaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång psykologiProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång spanskaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång engelskaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång matematikProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång svenska som andraspråkProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång svenskaProgram300 hp
  • Ämneslärarprogrammet med inriktning mot arbete i gymnasieskolan - Ingång biologiProgram300 hp
#177119
Apr 04, 2017 10:35
Vote:
 

In this case if i place the orange marked text in the beginning it will be corectly sorted.

#177120
Apr 04, 2017 10:37
Vote:
 

Can you post the Find query you are using?

#177121
Apr 04, 2017 10:38
Vote:
 

Well, it is this thats important for sorting (otherwise its only filtering it is the Alphabetically sorting that is not working after x charaters tryed whitout ThenBy, Not helping):

switch (filter.SortOrder)
			{
				case SearchResultSortOrder.Date:
					query = query
						.OrderByDescending(item => item.SearchMetaData["OrderByDate"].DateTimeValue)
						.ThenByScore();
					break;
				case SearchResultSortOrder.DateAsc:
					query = query
						.OrderBy(item => item.SearchMetaData["OrderByDate"].DateTimeValue)
						.ThenByScore();
					break;
				case SearchResultSortOrder.AlphabeticallyAsc:
					query = query.OrderBy(item => item.SearchTitle).ThenByScore();
					break;
				case SearchResultSortOrder.AlphabeticallyDesc:
					query = query.OrderByDescending(item => item.SearchTitle).ThenByScore();
					break;
			}

			return query
				.Skip(filter.PageIndex * filter.PageSize)
				.Take(filter.PageSize);


#177124
Apr 04, 2017 10:58
Vote:
 

Hi Niklas

I took a look myself and them getting the same results. I checked whether this varies between a regular search or unified but with the same result. I do know that unified will encode some of the characters, but that still doesn't explain the order issue.

I would raise this as a bug with Episerver. If there is a known limitation it should be stated.

What I would suggest in the meantime if possible is to have a separate property for sorting or trying something like .OrderBy(x => x.SearchTitle.GetHashCode())

#177130
Apr 04, 2017 11:48
Vote:
 

Janaka, Thanks for your answer... I will make a case conserning this to Epi...

#177136
Apr 04, 2017 12:38
Vote:
 

Ansver on ticket:

First:

Daniel (EPiServer/Ektron Support)

4 apr. 9:22 fm EDT

Hi Niklas,

Only the first 50 characters are used when sorting (orderby). 

I believe this limit somehow lies in how Elastic Search works and that fact the these fields are analyzed and tokenized. 
I'm gonna try and dig deeper and see if there a way around this.

Thanks,
Daniel

Last:

Daniel (EPiServer/Ektron Support)

18 apr. 5:14 fm EDT

Hi Niklas,

Sorry, it doesn't seem to be any easy way round this.
I believe this limit is for performance.

You should be split the data and put it in different fields and sort on both but I don't know how I feel about that approach.

Thanks,
Daniel

#177835
Edited, Apr 20, 2017 10:37
* You are NOT allowed to include any hyperlinks in the post because your account hasn't associated to your company. User profile should be updated.