The question was brought up a few years ago at:
My own experiments show that you can query e.g.
{{#ask: [[Person name::+]]
| ?Person name = name
| ?Person firstname = firstname
| limit=500
}}
and sort by firstname to show the entries that have no firstname. If you sort by firstname:
{{#ask: [[Person name::+]]
| ?Person name = name
| ?Person firstname = firstname
| sort=Person firstname
| limit=500
}}
the non-empty firstnames will not show any more
{{#ask: [[Person name::+]][[Person firstname::!+]]
| ?Person name = name
| ?Person firstname = firstname
| limit=500
}}
does not work as the not operator ! would suggest
actively says "no" it's not possible.
- https://github.com/SemanticMediaWiki/SemanticMediaWiki/issues/1073 was filed as a change request
What would be working with the current SMW version?
It looks like even a not operator does not work as expected:
{{#ask: [[Person name::+]] [[Person firstname::!Adolf]]
| ?Person name = name
| ?Person firstname = firstname
| limit=500
}}
will only show Persons that have a firstname that is not Adolf but not the person entries that have a name but no firstname.
To the best of my knowledge, the current range of facilities for selecting pages does not directly support searching for empty or missing properties.
I wouldn't hold my breath waiting for it to be implemented either because it's likely to be a little performance intensive to perform such a search. A little example to demonstrate:
Scenario: Your wiki has 3 properties, Prop1, Prop2, Prop3. There are 10 pages in the wiki.
Query 1: You are selecting pages based on the existing value of Prop1. Like
[[Prop1::Josef]]
. SMW sees Prop1 on Page 1 and stops evaluating the rest of Page 1 (i.e. Prop2 and Prop3) and moves on to Page2. So with this query, only 10 properties are evaluated, once for each of the 10 pages.Query 2: You are selecting pages based on the absence value of Prop3. Each property on each page must be evaluated in order to determine if that page is a match. If it seems illogical to evaluate Prop1 to see if Prop3 is empty, remember that the query engine first needs to determine if a property is Prop3 before it can evaluate the value of any Prop3 it finds. As a result, when querying for empty properties, the query engine must evaluate every property on every page which can potentially hold such an empty property.
That at least is my interpretation of the reason why there's no facility to check for empty or absent properties. I can see how it could be a cause for concern on larger sites from a performance perspective. I imagine if this feature shows up, it might do so in an extension to allow people to implicitly accept potential performance consequences by having to install such an extension.
In the meanwhile, there's a fairly reasonable workaround (I have the same need for empty or "not filled out" properties), and that is using the template to assign special properties when the template parameter is missing.
A simple example where template argument Prop should become the value of property ExampleProp:
This way you can query for the presence of the value UNDEFINED for the property ExampleProp instead of its emptiness. It isn't pretty but it works.