microsoft-search / pnp-modern-search

Home of PnP Modern Search solutions, helping you move from classic to modern SharePoint and beyond
https://microsoft-search.github.io/pnp-modern-search
Other
387 stars 340 forks source link

Search Results cannot be sorted by Title #1518

Closed h-h-o closed 2 years ago

h-h-o commented 2 years ago

Version used 4.4.1

Describe the bug When using the "PnP - Search Results" web part, sorting by Title either results in no results shown or in an error message ([HTTP]:500 - [CorrelationId]:325d03a0-40f8-c000-8f5f-766c5dff606e [Version]:16.0.0.21903) I discovered this with a Query template with some conditions that returns both Pages and Documents. And when results are available, switching to Sort order 'Title' always results in the error. But for reproduction purposes I was able to reproduce it with the default configuration of the web part.

To Reproduce Steps to reproduce the behavior:

  1. Go to a Modern Communication Site page
  2. Add the "PnP - Search Results" web part -> you should see a lot of search results
  3. Set the Sort Order to 'Title > Ascending'
  4. Web part now shows "0 results"
  5. Change the Query template to "{searchTerms} " (so adding the )
  6. Web part now shows an "[HTTP]:500" error

Expected behavior Sorting by 'Title' works

Screenshots No screenshots

Desktop (please complete the following information): Desktop: Tested with Firefox and Edge (Chromium), both are up-to-date

Additional context SharePoint Online Communication Site part of a Hub Search Results are fetched from other sites in the Hub

FranckyC commented 2 years ago

Hi @h-h-o, the Title managed property is not sortable by default in the schema so you can't use it:

image

You can update a RefinableStringXXX with the same crawled properties to achieve what you want.

h-h-o commented 2 years ago

Thank you @FranckyC

I don't know how I've missed that as I checked the managed property. But you solution is spot on, and I've got it working with a RefinableString.

One remark though. A RefinableString is always configured with "Include content from all crawled properties" and this cannot be changed. So rather than including all crawled properties from Title, you have to add only the ones needed for the content types in the search results to avoid duplicates.

schoier commented 2 years ago

@h-h-o @wobba "you have to add only the ones needed for the content types in the search results to avoid duplicates" How do you know what crawled properties that really are needed? Is there any way to get the value of a crawled property for a specific document?

wobba commented 2 years ago

@schoier no, but you can use the Search Query Tool to see which crawled properties are emitted for a result. To see the value you need to map it to a managed property.

image

SJNBham commented 1 year ago

We had trouble finding the crawled property for the Title column in a standard SharePoint Online list. Much of the online documentation pointed to ows_Title or other crawled properties. We ended up identifying ows_LinkTitle as a crawled property that stored the "Title" text we were looking to sort by. So we added ows_LinkTitle crawled property to the refinablestring01 managed property. Then we used the refinablestring01 as the field to sort by in the PnP search results web part sort config.

Thank you @wobba for the tip on using the SharePoint Search Query Tool.

wobba commented 1 year ago

@SJNBham see https://github.com/microsoft-search/pnp-modern-search/issues/2492 as you can use "Office:2" as well for title.

blumenhause commented 2 weeks ago

working on this issue with Microsoft for over 6 months now, its annoying they don't seem to know or involve right people to fix a basic search issue. On my SPO site I'm using PnP search webparts, refiners, and vertical components on a page to display results from several libraries in same site. I have tried mapping multiple crawled properties to a RefinableString that has sort enabled but no luck in getting results sorted by Title. So far tried crawled properties (and yes, I did full crawl and waited 24 hours and can see new results updated via search query tool):

  1. Office:2
  2. Basic:DisplayTitle (this is what MS support suggested to use)
  3. ows_Title
kasperbolarsen commented 2 weeks ago

https://www.m365thinking.com/post/fix-one-of-the-problems-in-sharepoint-search-make-title-sortable :-)