Help talk:Selecting pages/Archive


Sense of documentation[edit]

By using other categories or properties than above, we can already ask for pages which have certain annotations.

I don't quite get how this sentence is relevant to the text that is either preceding or following it?! --Reinout van Schouwen 10:11, 11 August 2008 (UTC)


It appears that if the predicate is [[category:X]] then the query fails. If the predicate is [[Category:X]] then the query succeeds. I do wish that SMW could fix that, auto-capitalizing the name of the namespace.

Searching for not set properties[edit]

I would like to search for properties, which are not set. How do I do that ? --Toka 22:54, 1 February 2010 (UTC)

Hi Toka, just go to "Special:SpecialPages" and the select "Special:WantedProperties" in the section "Maintenance reports". Cheers --kgh 23:34, 23 March 2010 (UTC)

I think there is a difference in "Special:WantedProperties" and what is being asked. I too would like to be able to see all pages that have not used a particular property. For example, If there is a property for phone number and some people have set up pages with a phone number and some have not, I would like to query to find those that have pages with no phone number property set. Thanks for any feedback.

I also want to select Pages without a particular Property. Any news on that issue?
+1 (asking the same thing).Ankostis 13:30, 10 December 2010 (CET)
same here Svdubl 17:00, 27 January 2010 (CET)
I should note that there's a workaround that's not ideal, but it works: if you're using a template to store the SMW data, you can have the template store some property like "[[No phone number::true]]" if there's no value for that template field, using the #if function - and then query on that. Yaron Koren 15:48, 27 January 2011 (CET)
That would indeed be very useful. I am using an "Action Item" triplet (Category/Template/Form), and would like to display all the items that have not set the "Completion Date" property. In the meantime, could someone give an example of how one would use the #if as mentioned by Yaron ?
{{#if:{{{foo_param|}}}| [[bar prop to apply::{{{someparam|}}}]]| [[no bar prop::true]]}} Ankostis 15:11, 26 May 2011 (CEST)
You can also define an array (using the Array Extension) to the result of an #ask query for all pages (or at least the ones in the main namespace, or whatever), then another one with an #ask for all pages with that property set, then #arraydiff them to create the array of pages without the property set. Not ideal, but I think it's cleaner than adding another property, and works even if you don't set that particular property with a template. It sounds like a pain in the butt, but all you have to do is make a template with something like
and call it like {{name of template|name of array|name of property|additional qualifiers}} and then #arrayprint the result (it'll be called whatever you specified to be name of array) however you like.

--EvgeniyDankovcev 04:26, 16 December 2011 (CET) I found a different workaround that worked in my case. say, we ask for animals inside a category animal and output ones that have age not set. {{#ask: [[Category:Animal]]|?Age|format=template|template=Animals without age}}. inside a template Template:Animals without age: <includeonly>{{#if: {{{2}}} | | {{{1}}} }}</includeonly>

NB it's not an optimal performance query since it actually selects all animals instead of selecting only ones that don't have age NB2 for this to work you must have parser function extension turned on

Searching for pages NOT in Categories[edit]

How do you select pages with an non-set category in a query? E.g. if we had a 'NOT' operator, it might be {{#ask:NOT [[Conclusion::+]]}} to look for pages without the 'Conclusion' category set. I have tried [[Conclusion::]], [[Conclusion::!+]], [[Conclusion::!]] and [[Conclusion::'']] with no luck. Thanks, Mark J Dayel 21:35, 25 March 2010 (UTC)

Me also needing this feature. Ankostis 13:28, 10 December 2010 (CET)
Yah. Would be extremely useful operator. - Lbillett 2011-02-10
Yes! Such a feature would be very helpful indeed! --Gollum 13:16, 21 July 2011 (CEST)
I absolutely support this. There are a sh!loads of usecases, fx {{#ask: [[Category:A]] NOT [[Category:B]] --Eric 21:54, 27 September 2011 (CEST)
+1. This would be a very helpful feature! Stefahn (talk) 13:45, 23 November 2013 (CET)
Would be very helpful. Also page names and namespaces should allow negation (with a minus perhaps).
Alex Mashintalk 19:37, 23 November 2013 (CET)

distance calculation[edit]

The distance calculation, described at LIKE comparator seems not to work since SMW 1.5.0 It was a great function! Why it had been removed??? -- 18:21, 8 March 2010 (UTC)

It hasn't been removed - it just got changed, and moved into Semantic Maps. See here. Yaron Koren 01:10, 12 July 2010 (UTC)


Hope not to offend anyone by pointing to two misspellings and one bad phrasing in the article:

  • ...that might be use...
  • the smae page...
  • Comparators work only for property values, but not for conditions on categories: Only and but should not be used together. Replace but by and or leave out only.

--Even Thorbergsen 19:33, 23 March 2010 (UTC)

Hi Even, thank you for your hints. I do not think that someone will feel offended by your input. It helps making this wiki even better. Cheers --kgh 20:10, 23 March 2010 (UTC)
Kept on reading after a break and found this: special sybols--Even Thorbergsen 22:27, 23 March 2010 (UTC)
I would not have found the last one if had done a refresh before reading on, as someone in the meantime had performed a cleanup. Still I found this: A Italian city.--Even Thorbergsen 22:38, 23 March 2010 (UTC)
Sometimes changes happen fast on a wiki. :-) Thank you. --kgh 23:04, 23 March 2010 (UTC)

Filtering out deleted pages?[edit]

If someone (say, me) creates a category, but accidentally misspells it, then deletes it, it then shows up in any category query from then on. How to filter on MediaWiki meta-data like 'deleted' or 'last-updated' is not very well explained on this page.

I bet the issue is that, after you misspelled it, you moved it to its correct spelling - which then caused for there to be two category pages, the first being a redirect. You should delete that redirect page as well. Yaron Koren

UPDATE: Figured out the problem. Once SMW knows about something, it refuses to forget about it. I deleted the redirect page. I deleted the history. It was still there. I scoured the MediaWiki database. There was no trace of the old page. In order to make it go away, I had to go into the database and delete the rows in the SMW_IDS table. Even using the 'SMW_refreshData.php' script in the SMW/maintenance folder didn't solve the problem. So, for fun, I deleted all rows from SMW_IDS table, then ran the SMW_setup.php script, which re-created the built-in rows from that table, then ran the SMW_refreshData.php script, which populated the table with all the stuff that used to be there and still belonged there.

The fact that rows are never removed from that table, even after they are removed from the rest of the wiki, is (I think) a defect in SMW. True, in most wiki's you don't delete pages, you create redirects. So it's probably not a huge deal for most people. But at least there is now a documented workaround.

If someone has the Parser Functions extension installed. You can use {{#ifexist: *pagename*|*true statements*|*false statements*}}
A specific example for your categories would be {{#arraymap: {{#ask: [[:Category:+]]|link=none}}|, |cat| {{#ifexist: cat | [[cat]] | }} |}}
That's as pretty as it gets, unless you add a property into the non-deleted category: such as [[Is alive::{{PAGENAME}}]]
Then it's as simple as {{#ask: [[Is alive::+]]}}
Here is another idea I found at If you add the condition [[modification date::+]] to your query then it will only return pages that exist. So, <nowiki>[[:+]] [[modification date::+]] returns a list of all existing pages in the main namespace. And [[:Category:+]] [[modification date::+]] returns a list of all existing categories. However, I could not get this to work with a list of templates as it appears that templates do not have the modification date, or any other, property. --Marnicknz 10:55, 1 February 2011 (CET)
This does not work for properties either. Everything has a modification date. The only reason it's not working is because, I guess, some things were overlooked. My impression of mediawiki in general is that features get added haphazardly without much big-picture planning. Without a big picture plan, there ends up being more than one way to do things, and whatever way you're doing it that doesn't work is the "wrong" way. Of course, over time, every oversight is hopefully identified and fixed. I just hope this one gets fixed, since it seems like a pretty fundamental oversight for something that bills itself as a semantic wiki, not just an isolated semantic page. If it weren't supposed to be a semantic wiki, I may not expect the semantic features to work on everything. But, I guess there isn't much use for something that's only partly semantic, since that sharply constrains the flexibility that the semantic features are supposed to offer. So where does that leave us? With a broken semantic wiki, unfortunately. Badon 04:37, 12 July 2011 (CEST)
My mistake, it does actually work for properties. In fact, it seems it works for everything, including templates. The issue is that you need to add the template namespace to SMW, and then you have to actually modify the the template to get it to have a modification date. This should be helpful:'s_data Badon 20:03, 15 July 2011 (CEST)

I have all these same problems. I consider them to be serious bugs. I can't believe it's been known for so long and not fixed. I'm doing the exact same thing, with trying to display templates, categories, properties, forms, etc, and I get huge lists of old, deleted stuff, if I get anything at all. This is unexpected. How does this get fixed? After this many months, if nobody else can do it, I suppose I better have a look at the code myself, and see if I can fix this. My project has been halted because of this. Badon 02:43, 12 July 2011 (CEST)

It looks like it wasn't fixed because it wasn't formally reported as a bug until quite recently. Now that it's been reported, hopefully no more modification date tricks will be needed to get this to work. Badon 20:05, 15 July 2011 (CEST)
I have also run into this problem. Is there any update? I'm using SMW (upgraded in January 2012). I understand it has not been fixed yet? OUA 13:38, 20 March 2012 (CET)
It was not fixed in case your wiki shows the reported behaviour. Since the bug id was not shared you and I cannot really have a look. Cheers --[[kgh]] 23:34, 20 March 2012 (CET)
Still not fixed it seems. I had a page in a custom namespace accidentially the created with the pagename "&" and deleted. It not was still appearing in results as a redlink and also the result set got mulitple entries for all results, each with strange numbers attached. Both, the deleted page and multiple results vanished afer adding Modification date::+ to the query.

Selecting pages that are properites of another set of pages[edit]

I can't find a way to select pages in the following way: Let's say I have this set of data:

  • Category images that contains
    • File 1 that has property [[file type::jpg]]
    • File 2 that has property [[file type::png]]
    • File 3 that has property [[file type::jpg]]
  • Category file types that contains
    • jpg page
    • png page
    • ocx page
    • txt page and so on.

Now I would like to select pages from category file types that are used by pages in category images. The query should return pages jpg and png (not File 1, File 2 and File 3). Of course the file type property is of type Page.

Is it possible to do that? If yes: how? Any help will be appreciated. 09:54, 1 September 2010 (UTC)

Wildcards and comparators in article names and categories[edit]

It will be helpful to enable the use of wildcards and comparators while searching not only by property but also by category and page name, e.g.: {{#ask:[[Located in::Germany]] [[!Berlin]] [[Category:!Land Capitals]]|intro=German cities that are not federal or land capital}}. -- Anonymous

Help does not mention the Search Inverse Property of v1.5.0 feature[edit]

The *very* important feature Inverse_properties is not mentined at all on this help-page. Probably a separate section should ve devoted for it. Ankostis 12:52, 13 December 2010 (CET)

Date related questions[edit]

How can I search for pages which have a Modification date less than a specific date?[edit]

The following example should help.

{{#ask:[[Modification date::≤29 February 2012]]
|?Modification date
|sort=Modification date

Date sorting not working[edit]

I'm using the following "#ask" query in my private wiki, but the sorting is not working. Note that the "Due Date" property is of type Date. Am I doing something wrong ?

 {{#ask: [[Category:Team_Actions]] [[Due Date::>{{#time: Y-m-d}}]] [[Action Status::!Canceled]] [[Action Status::!Completed]] 
|?Due Date=Deadline
|?Actionee=In charge
|?Action Status=Status
|?Action Description=Description
|sort=Due Date

Problems combining <date> and <!date>[edit]

Hello, can someone with more brains than me explain why this fails: [[DateProperty::1912-08-10]] [[DateProperty::!1912-08-09]]? It seems that the second part is completely ignored. What I want to return is articles with date 1912-08-10 that do not also have date 1912-08-09. (Link to Special:Ask)

The properties are set (via templates) similar to this:

{{#set_recurring_event:property=DateProperty |start=1912-02-01T00:00:00 |end=1912-09-31T00:00:00 |unit=day |period=1 }

Best regards, Rotsee 16:08, 8 April 2011 (CEST)

Or is it in fact returning any page with a property DateProperty set on anything but xxx? I guess so. In that case I guess I have to do my own extension to handle it, unless there is some clever workaround. Rotsee 16:17, 8 April 2011 (CEST)
Workaround: Add an extra property: StartingDate at first day of period each, and check for that instead. 19:35, 8 April 2011 (CEST)

Can't list contents of categories[edit]

I have an odd problem: When trying to show pages in a category, e.g. by {{#ask: [[Category:xxx]]}} all I get is one line, with the category name (like this:, rather than a list of pages in that category, which I had expected. Does anyone have an idea what's going wrong here? Rotsee 23:56, 11 March 2011 (CET)

Solved: I had to use local name for categories (that wasn't entirely clear from the docs here, and I also had to grant the wiki database user a couple of extra mysql rights Rotsee 00:11, 12 March 2011 (CET)

Default values for missing properties[edit]

Is there a way to supply a default value for a property if it does not exist in a row? Would be useful for formatting queries with templates.

E.g. I use a template called Titled Internal Link, which takes to parameters, page and title property. It simply queries the title property and displays it after the pagename. If I have a query which produces a list of pagelinks which I want to format with this template, I have no way to supply the second parameter to the template. Defining defaults in the template itself would not help in my case.

I'm pretty sure there's no way to do that. Yaron Koren 19:53, 25 March 2011 (CET)

select distinct value of property[edit]

Is it possible to ask like this:

select distinct town from friendlist;

At the moment I ask:

{{#ask: [[Kategorie:Friends]] | ?Town= | mainlabel=-}}

and get a long list of town with many duplicates.


I'd rather like a result like:


Is this possible?

-- 20:55, 17 April 2011 (CEST)

I might have missed something, but I think not. Most of the time you should be able to achieve what you want by rethinking your semantic structure a bit, though. When I've found myself in a corner like this, it has always been because of not thinking through my structure before starting to build. Can you describe exactly what you are trying to do? Rotsee 16:50, 27 April 2011 (CEST)

-- 16:17, 18 May 2011 (CEST)

See for one answer to this. It does require use of ArrayExtension to work, but that extension is included with SemanticBundle. Matt V.

--Svdubl 05:58, 18 July 2012 (CEST) there is a different workaround which might work for some. faceted query result format allows to group by property values and thus gives a list of unique values as one of facets

NOT for page-type pages?[edit]

See Help talk:Inline queries#NOT for page-type pages?. Cavila 17:03, 27 November 2011 (CET)

Parenthesis for unions[edit]

Hi. Why can't I use () to group several OR and AND in queries? It shows an error. Is it supported? Emijrp 01:40, 30 January 2012 (CET)

I guess not. When I have several ORs I use a concept to preselect pages. This might be a solution for you too. Cheers --[[kgh]] 14:25, 30 January 2012 (CET)
I have a similar question/problem: The following query doesn't work as expected:
But when I put the OR query at the end of the query it works just fine:
Anyone can explain this?
--Stefahn (talk) 13:12, 5 September 2012 (CEST)
I guess that the query works on the first part of the query description first and after having selected the pages it does the second part of the query description on exactly these pages selected by the first part. This would explain the different results when exchanging the two parts of the query description with one another. I as SMW would do it like this. :) Still I am not absolutely sure. Why not post this to the mailing list? Cheers --[[kgh]] (talk) 18:43, 5 September 2012 (CEST)

Wildcard * is counter intuitive[edit]

In most (all?) computer languages that use this wildcard it means "zero or more characters", while in SMW it somehow is "one or more characters".
Could this be corrected to keep everyone sane? :D
Thanks a lot.
--TriMoon 06:20, 24 July 2012 (CEST)

Hi, this is something you should post on the developers mailing list. They will most probably not notice your post here at all. Cheers --[[kgh]] 10:25, 24 July 2012 (CEST)
There are no threads on this page yet.