"sort" option in query does not include results that have no value in sorted field

From semantic-mediawiki.org
Edited by another user.
Last edit: 22:23, 4 March 2014

Hello,

The following query brings up no results (because Begin Date is blank):

{{#ask:[[Category:Market research]]
|?ResearchStatus
|?ResearchType
|?Description
|sort=BeginDate
}}

But this query brings up all results:

{{#ask:[[Category:Market research]]
|?ResearchStatus
|?ResearchType
|?Description
}}

I don't think that it logically follows that a "sort" option should exclude results where sorted field is blank.

22:00, 4 March 2014

Well, if you do not query for a property you cannot sort by it since your printout statement cannot be fulfilled. Somehow you have to pick up the date from the pages/subobjects with the query. See sorting results. So your query should be

{{#ask:[[Category:Market research]]
|?ResearchStatus
|?ResearchType
|?Description
|?BeginDate
|sort=BeginDate
}}
22:29, 4 March 2014

This is about sort statements that filter out the rows in which the sorted field is null, I think. An old and already reported problem of SMW.

03:42, 5 March 2014
 

A simple workaround to this is to define, in the template, some default values for the properties of interest if they are not already set. ie:

{{#if: {{{ArgIwant|}}}||[[PropIneed::SomeDefaultValue]]}} 

It's more elegant to do it where it's actually printing, but this has overcome the whole 'sort' issue any time I've needed it. Though, it assumes all the articles call some templates to which you could do this.

04:56, 6 July 2014