Copied to clipboard

Flag this post as spam?

This post will be reported to the moderators as potential spam to be looked at


  • Debasish Gracias 32 posts 163 karma points
    Aug 12, 2024 @ 07:07
    Debasish Gracias
    0

    Examine sorting by string not working in Umbraco 10

    Hi all, We want to be able to sort the results based on a string field(aggregationTitleSortable). This is what we have done so far but it is not sorting the results alphabetically.

    public class ExamineComposer : IComposer
    {
        public void Compose(IUmbracoBuilder builder)
        {
            builder.Services.ConfigureOptions<ConfigureExternalIndexOptions>();
        }
    }
    
    public class ConfigureExternalIndexOptions : IConfigureNamedOptions<LuceneDirectoryIndexOptions>
    {
        public void Configure(string? name, LuceneDirectoryIndexOptions options)
        {
            options.FieldDefinitions.AddOrUpdate(new FieldDefinition("aggregationTitleSortable", FieldDefinitionTypes.FullTextSortable));
        }
    }
    

    Search Service

    public SearchResponseModel ServicePartnerSearch(SearchRequestModel searchRequest)      
     {
         IBooleanOperation? query = index.Searcher.CreateQuery(IndexTypes.Content).NodeTypeAlias("servicePartnerPage").And()
                 .GroupedNot(new string[] { "umbracoNavHide" }, new string[] { "1" });
    
         if (searchRequest.SelectedPartnerTypeTags != null)
         {
             query.And().GroupedOr(new string[] { "partnerTypeCustom" }, searchRequest.SelectedPartnerTypeTags);
         }
    
         if (searchRequest.SelectedContinentTags != null)
         {
             query.And().GroupedOr(new string[] { "continentCustom" }, searchRequest.SelectedContinentTags);
         }
    
         query.OrderBy(new SortableField("aggregationTitleSortable", SortType.String));
         ISearchResults? pageOfResults = query.Execute(new QueryOptions(searchRequest.Skip, searchRequest.PageSize));
    
         return new SearchResponseModel(searchRequest.Query, pageOfResults.TotalItemCount, pageOfResults);
     }
    

    I can see the value getting correctly set also.(screenshot attached) enter image description here

    Can someone please point me if I am doing something wrong?

  • Debasish Gracias 32 posts 163 karma points
    Aug 14, 2024 @ 08:57
    Debasish Gracias
    0

    Hi all, needed your inputs on this. Has anyone been able to sort based on a string in umbraco 10?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 14, 2024 @ 14:33
    Huw Reddick
    0

    Don't have an answer I'm afraid, I did do some tests and couldn't get it to work either.

  • Debasish Gracias 32 posts 163 karma points
    Aug 15, 2024 @ 08:04
    Debasish Gracias
    0

    Do you reckon its a bug with examine in umbraco v10?

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 15, 2024 @ 08:12
    Huw Reddick
    0

    I'm getting the same results in v13 too, will have a play around later and see if I can get anywhere

  • Debasish Gracias 32 posts 163 karma points
    Aug 15, 2024 @ 09:28
    Debasish Gracias
    0

    Thank you so much! Really appreciate your effort in trying to troubleshoot this issue

  • Huw Reddick 1929 posts 6717 karma points MVP 2x c-trib
    Aug 15, 2024 @ 13:15
  • Debasish Gracias 32 posts 163 karma points
    Aug 21, 2024 @ 17:24
    Debasish Gracias
    100

    I have written an article explaining the solution here https://www.debasish.tech/blogs/how-to-sort-on-a-string-field-in-umbraco-examine

Please Sign in or register to post replies

Write your reply to:

Draft