Sorting Search Results and Cadinality Of Properties

The structWSF Search web service endpoint supports the sorting of results by setting the values of some properties. What we will see in this article is the effect of properties' cardinality of the sorting feature of the Search endpoint.

How Sorting Works
The sorting feature of the Search endpoint can sort results of a resultset according to one, or multiple, sorting criteria. Each sorting criterion is a property URI which refers to the values by which we want to sort results.

However, there is one restriction:

the cardinality of the property has to be 0 or 1

This means that only those properties that can have a single value can be used to sort a resultset. Multi-valued properties cannot be used to sort a resultset.

Existing and Example Properties Available for Setting Sort Selections
By default, only the core attributes:,  ,  ,   and   are available for sorting content with the Search endpoint. Additionally, properties such as,   or any other may be defined as being sortable using one of the techniques described in this document.

For other circumstances, it is possible to add other properties with the cardinality descriptions as outlined herein that could, for example, provide sortable fields for:
 * Popularity
 * Record completeness
 * Last updated
 * Links in or out (a la Page Rank)
 * Price
 * Rating
 * etc.

These properties should be defined in advance and handled as described in the steps below.

How to Change the Cardinality of a Property
The cardinality of a property has to be specified in the ontology where the property is defined. Also note that this ontology has to be created in the structWSF instance, otherwise the Search endpoint won't be aware of the cardinality of the property and will consider that it has no maximum cardinality by default.

There are two ways to change the cardinality of a property:


 * 1) Add one of these triples into the ontology where the property is defined:
 * 2) Using the structOntology user interface, changing the cardinality of the property. The cardinality can be changed in the   section of the properties tab.
 * 1) Using the structOntology user interface, changing the cardinality of the property. The cardinality can be changed in the   section of the properties tab.
 * 1) Using the structOntology user interface, changing the cardinality of the property. The cardinality can be changed in the   section of the properties tab.

Enabling Sort On a Property: All the Steps

 * 1) Specify that the cardinality of the property is maximum 1
 * 2) You can do this by:
 * 3) Adding one of these triples into the ontology where the property is defined:
 * 4) Importing that ontology into structWSF by using the Ontology Create web service endpoint or the structOntology user interface.
 * 5) Using the structOntology user interface, changing the cardinality of the property. The cardinality can be changed in the   section of the properties tab.
 * 6) Then you have to click the "generate all" button in structOntoloty to re-generate the underlying ontological structures, which include the structure used by structWSF to manage that new single-valued properties, and this new sort property by the Search endpoint.
 * 7) Re-import all the datasets in which this property was used
 * 1) Then you have to click the "generate all" button in structOntoloty to re-generate the underlying ontological structures, which include the structure used by structWSF to manage that new single-valued properties, and this new sort property by the Search endpoint.
 * 2) Re-import all the datasets in which this property was used

sco:cardinality, sco:maxCardinality and sco:minCardinality
The cardinality of the properties needs to be defined with the annotation property  or.

These properties are used to define how many values are expected to be used to describe a single record for that property.

Impact of Cardinality on Existing Indexed Content
If you change the cardinality of a property in the ontology, you have to re-index all the datasets where the property is used. This means that you have to update each record that uses this property by using the CRUD: Update web service endpoint, or by deleting the dataset using the Dataset: Delete endpoint and by re-creating/re-importing the dataset using the Dataset: Create and CRUD: Create web service endpoints.

If you change the cardinality of a property, without re-indexing the content that uses that property, you may experience some unexpected behaviors when using the Search web service endpoint.

It is necessary to do this because of the way that the Solr index, and Solr, are working.

We recommend to define the sortable properties before indexing all the content into your OSF instance.