digitalutsc / islandora_lite_docs

Contains a Wiki with documentation for the UTSC Library's Islandora Lite System
GNU General Public License v3.0
2 stars 0 forks source link

Add sorting in Federated Search #65

Closed kstapelfeldt closed 1 year ago

kstapelfeldt commented 1 year ago

Sort by title, relevance, date, etc

amym-li commented 1 year ago

Sorting

Repo: ajax_solr_search/sort

Configuration

An implementation of the sorting feature can be found at the link above. The SortSelectWidget features a dropdown menu that allows users to sort their search results based on the configured sort criteria. The sort criteria can be configured on the federated search config form at /admin/config/search/ajax_solr under the Sort Criteria section. The order in which the sort criteria is displayed in the dropdown can be modified by rearranging the order of the field entries on the form. A sample configuration can be found in README.md.

Multivalued Sorting

Solr does not support sorting on multivalued fields. Currently, the config form allows users to select multivalued fields as sort criteria, but if they try to select them when sorting, the results will appear to load indefinitely (Solr returns Error 400 bad request).

I created a patch [sort_criteria.patch] that prevents this by removing multivalued fields from the list of available fields when configuring sort criteria. I've tested this against my local Solr server with proxy disabled, but I'm not able to test it with proxy enabled so it hasn't been committed yet.

Also, I found a workaround for sorting on multivalued fields using function queries (see: field Function), however, this only works for numeric fields and can't be used for Text/String fields.

Update

The patch file [sort_criteria.patch] currently does not work with proxy enabled. (It's using the wrong Solr url for the curl requests) Todo: Add schema/fields/ route to the routes yaml file and add the FilterOutMultivaluedFields function to Proxy Controller.

Case Sensitivity

Sorting by string fields in Solr is case-sensitive. I was not able to find a way to override this behaviour by modifying the queries themselves. I'm using the Default Solr content index for Islandora Lite, and most of the single-valued text fields seem to be stored as string so this might be an issue when sorting by fields such as title. I tried indexing title as Fulltext but all the Fulltext options are multivalued which can't be used for sorting.

A possible solution could be to use solr.LowerCaseFilterFactory but that can only be used for Text fields and not String fields. Also, this approach would require modifying the Solr schema.