Help talk:Selecting pages

Jump to: navigation, search
Please note

Talk pages on this wiki should primarily be used to address possible mistakes as well as missing and superseded information in the documentation.
In case you are seeking support concerning individual questions, please have a look at this page.
The SMW user mailing list is always a good idea for seeking help.

Please note


Selecting pages with non alphanumeric values for their Label

Hey, we're currently having this problem: on our SMW all pages created with a form automatically get a Semantic Property "Label" that has the same value as the page name, so that we can search for it with #ask by querying on XYZ. However, if the Pagename, or really any other Semantic Property, contains non alphanumeric characters such as ' " & the #ask fails (even in the Special:Ask page). I tried escaping or double-escaping the characters with backslashes but that does not work. If it can help, the property datatype is set to String and does not generate warnings with those "unsearchable" values.

FMalvisi (talk)10:54, 7 October 2016

> currently having this problem: on our SMW all pages created with a form automatically get a Semantic Property "Label" that has the same value as the page name, so that we can search for it with #ask by querying on XYZ > alphanumeric characters such as ' " & the #ask fails (even in the Special:Ask page). I tried escaping or double-escaping

When reporting an issue you should always state the version (MW, SMW, SF etc.) you referring to. Aside from the unclear version, I'm a little bit unsure about the problem itself and the description is bit too ambiguous to pinpoint to a possible cause. I'd suggest you try to recreate your problem on [1] so that interested parties or developers can clearly understand the circumstances of your problem and have a reference to what your are referring to as `... contains non alphanumeric characters such as ' " & the #ask fails ...`.


MWJames (talk)04:35, 9 October 2016

Hey James, sorry for the confusion, what I mean is something along these lines:

I have a page with a Semantic Property that has a value that contains characters such as single quotes, double quotes or "&", such as the property Has text of this page

If I now run the queries that I setup in this page on my wiki, the only one that works is the second. The first and the third one show no results.

My wiki runs on MW 1.25.1 SMW 2.2.2 Semantic Forms 3.4 I tried to update SMW to 2.4.x on a local VM and the issue persists. The language of the wiki is set to Italian, if it can matter at all

Thanks for your patience

FMalvisi (talk)10:47, 10 October 2016

Filtering deleted pages seems not to work with SQLStore3 as well

Similar to the problems already mentioned with the old store, I ran in problems with deleted pages showing up as result with SMW1.8 on MW 1.20 using SQLStore3. I consider redirects to be part of the problem as well. As there is no bug referenced in the other thread on this page: Has the problem really been properly adressed and solved yet?



Argi (talk)09:29, 27 February 2013

See bug 42896 which is still open.

[[kgh]] (talk)01:13, 28 February 2013

Has this problem been solved in the meantime? The problem with deleted pages showing up as result also occurs with SMW 2.0 / MW 1.23.8

Kappa (talk)17:12, 8 January 2015

I'm not aware that this issue still persists in 2.0. If you can a provide a producible scenario and post it on [0] with reference to this thread (together with the versions used MW/SMW/+ other SMW related extensions). [1] is related to the SPARQLStore and was fixed in SMW 2.1.



MWJames (talk)18:29, 8 January 2015

Thank you very much for looking into my test wiki and for your analysis. Since I think the answer you sent me might be interesting for other people as well, I post an extract of your mail here:

MWJames mailed on 9 January 2015 at 18:18: Your ask query actually means "give me all pages in namespace Test" because Test: is registered as separate NS.

{{#ask: [[Test:+]]
| ?attribute1
| ?attribute2

Since it is an unconditional query, it returns all possible pages even those deleted because the SQLStore doesn't delete a subject entry it sets it to be empty [0] leaving the subject (Page3/Page4) to remain in the smw_object_ids table. See also note [1], which states that "TODO: Possibly delete ID here (at least for non-properties/categories, if not used in any place in rels2)"

I added a simple condition to the query and got rid of the empty pages in the result:

{{#ask: [[Test:+]] [[attribute1::+]]
| ?attribute1
| ?attribute2

MWJames, thank you very much for your fast reply and your analysis.

Kappa (talk)19:44, 9 January 2015

Excluding property/category/specific page?

May I ask if there's a way to exclude a specific page/property/category from a search or #Concept? I see here that we cannot use the ! exclamation point to exclude properties, but I wonder if there is another way?

For example, I have a #Concept with {{[[Category1]] [[Property1]] [[Property2]]}}, but don't want a child Category (of Category 1) to be included. I can exclude it by a number of attributes, including the sub-category, properties, or specific page names. Is there a way to do this?

Worse comes to worst, can I go to those several pages I want excluded and add a new property so it is excluded in the search? For example, add a show_on_search::false, but without having to go into all the other pages (those to be included) and add show_on_search::true on them?


Aigo (talk)04:37, 8 November 2014

Category or page cannot be excluded. A certain value of property can: [[Property::!Value]] will yield all pages where Property is set but not to Value.

A workaround is using a template with {{#if:...}}<code>. Or Lua.

Alexander Mashintalk07:15, 11 November 2014

Grouping ORs with ANDs in arrays

Wow, been spending all day trying to get this working correctly. I have a SemanticForms RunQuery with a form entry that asks for a location. I'd like for the ability to put in "Texas" or "Austin" or "Austin, Texas". The first two are easy, but having the entry work with an array of "Austin, Texas" is proving a nightmare. If I manually type in

{{#ask:[[City::Austin||Texas]] [[State::Austin||Texas]]}}

I get what I'm looking for. Austin is matched with City, Texas is matched with State, and only Austin locations are shown. If I try to use an array or variable like

{{#ask: [[City::{{#arraymap:{{{Entry|}}}|,|x|x|<no*wiki>||</no*wiki>}}]][[State::{{#arraymap:{{{Entry|}}}|,|x|x|<no*wiki>||</no*wiki>}}]]}}

I get an Error: the value was not understood. I feel like I've tried everything. I've even tried to do a vardefine before the ask, and then ask on the var. Any ideas on how I can get this to work? Thanks

D3mon187 (talk)22:39, 16 November 2012

It's probably the double pipes that don't work, even when enclosed within nowiki tags (btw, why the asterisk?). I'm not sure if I understand you correctly, but is the intended query equal to the following one?

{{#ask: [[City::Austin]] OR [[City::Texas]] [[State::Austin]] OR [[State::Texas]]

In that case, this should do the trick, right?

{{#ask: {{#arraymap:{{{Entry|}}}|,|x|[[City::x]]|OR}} {{#arraymap:{{{Entry|}}}|,|x|[[State::x]]|OR}} 
Cavila (talk)19:28, 30 April 2013

Define a template {{!}} as | and try to use the template as the separator in {{#arraymap:}}: {{!}}{{!}}.

Alex Mashintalk19:55, 30 April 2013


OR {{#arraymap:{{{Entry|}}}|,|@@@@|[[City::@@@@]]|OR}}

AND [[City::{{#arraymap:{{{Entry|}}}|,|@@@@|@@@@|{{!}}{{!}} }}

[[kgh]] (talk)18:12, 3 December 2014

Non-existing pages

Am I correct in saying that this page (and related) doesn't say how to to make queries list (only) non-existing pages i.e. red links, nor whether it's impossible? Or is it implied somewhere I'm not seeing? Perhaps it's implied somewhere that a page must exist for a semantic property to be declared about it?

Example: I want to make a list like , but for pages which don't exist.

Nemo bis (talk)19:24, 2 November 2014

No, it is not possible to query for non-existing information. Setting a boolean property on existing pages for links which point to non-existing pages using the #ifexist parser function may be a way out. Thus you can query for this information.

[[kgh]] (talk)10:37, 3 November 2014

Ok, thanks. Now, where to mention this assumption of the docs? The answer came to me when I thought a while about it, but it's not so obvious.

Nemo bis (talk)22:14, 7 November 2014

Semantic Maps

Hi All,
I am a newbie in Mediawiki.
I have a property Country with all countries as value.
And i have Project form having Counties field (Multi-select) [i.e ABC project is on 2 Countries (India and China)]
Now, for example
ABC => India, China
DEF => China, Japan
PQR => India, France

I want to build a map showing markers based on Countries [Property]
For Example,
India marker should show "ABC, PQR"
China marker should show "ABC, DEF"
Japan marker should show "DEF"
France marker should show "PQR"

Please anybody help to build the query and show the map of Projects based on Countries

Pkapils (talk)13:36, 26 September 2014

Case insensitive query possible?

I have a search RunQuery that I would like to be case-insensitive. Is this possible? It seems the Like function used to be case insensitive, but isn't anymore. My query looks like this:

D3mon187 (talk)16:56, 5 November 2012

I haven't found any configuration settings or query settings to make a query case insensitive. I think you have to do a feature request in the mailing lists.

Yury Katkov (talk)11:52, 10 November 2012

Check your database collation.

Alex Mashintalk11:56, 17 November 2012

I was thinking about changing the collation, but I know very little about mysql. In phpmyadmin I found a table called smw_ids, but not sure if this is where to make the change. Clicking on structure, there was no collation shown on any of the rows. I tried changing the title and sort_key to utf8-general-ci, but it still didn't show anything set for collation in these rows. Anyone know where/how to make the change? Thanks

D3mon187 (talk)20:55, 19 November 2012

This is a long-standing feature request, but yes, the answer tends to be "change your collation". Unfortunately, no one has been able to tell how to do so in a safe way (e.g. in phpmyadmin).

Cavila (talk)19:42, 30 April 2013

I've managed to get case insensitive ask queries in MW 1.21.1, SMW, by setting the character set and collation, and changing 3 columns from varbinary to varchar.

  1. During the database step in the mediawiki installation, choose UTF8 as the database character set. (If binary was chosen the DB needs to be recreated and pages migrated). Note that issues have been noted by other users with UTF8 and some languages, so test this thoroughly if using a language containing special characters.
  2. Backup database using mysqldump
  3. Open MySQL Workbench as the root (or other authorised) user
  4. Run the following script:
use [Your_Wiki_DB];

/* The following show the character set (expecting utf8) and the collation (expecting utf8_general_ci) of the database, respectively.  
 * Uncomment and run against the relevant database to show the default settings. 
 * Note that changing these does not affect existing tables. 
--show variables like "character_set_database";
--show variables like "collation_database";

/* The following alter the relevant columns in the SMW tables to get case insensitive searching working */
-- smw_title
ALTER TABLE [Your_Wiki_DB].smw_object_ids change smw_title smw_title_bak varbinary(255);
ALTER TABLE [Your_Wiki_DB].smw_object_ids ADD smw_title VARCHAR(255) AFTER smw_namespace;
update [Your_Wiki_DB].smw_object_ids set smw_title = cast(smw_title_bak as CHAR) ;

-- smw_sort_key
ALTER TABLE [Your_Wiki_DB].smw_object_ids change smw_sortkey smw_sortkey_bak varbinary(255);
ALTER TABLE [Your_Wiki_DB].smw_object_ids ADD smw_sortkey VARCHAR(255) AFTER smw_subobject;
update [Your_Wiki_DB].smw_object_ids set smw_sortkey = cast(smw_sortkey_bak as CHAR) ;

-- smw_di_blob
ALTER TABLE [Your_Wiki_DB].smw_di_blob change o_hash o_hash_bak varbinary(255);
ALTER TABLE [Your_Wiki_DB].smw_di_blob ADD o_hash VARCHAR(255) AFTER o_blob;
update [Your_Wiki_DB].smw_di_blob set o_hash = cast(o_hash_bak as CHAR) ;
5. Case insensitive searching should now work

Note that you may get an error with the UPDATE statements if your preferences in MySQL Workbench are set with "Safe Update" on. This can be turned off by going to Edit>Preferences...>SQL Queries tab. Then uncheck "Safe Updates"... and reconnect to the DB.

Renae (talk)01:15, 10 October 2013

Note that the SQL table changes will be reverted if you upgrade your SMW version, so would need to be reapplied. Painful I know, but for us case insensitivity is mandatory.

Renae (talk)22:09, 29 October 2013

You can try query like as workaround.. It won't work for vAlUe, but might help to solve it.

Exbe (talk)23:06, 3 April 2014

A workaround that does not require changing database collation is setting another property to capitalised value of the first one and querying it.

Alexander Mashintalk04:19, 18 August 2014

How does one "SUM" and "GROUP BY"?

Hi all,

I'm trying to select a set of data and do a "SUM" and "GROUP BY" on the result.

I have the following ask:

{{#ask:[[Category:Knowledge Transfer Log]]

Which results in this:

                Date            Total 
Item 0004 	29 April 2013 	5 	
Item 0005 	6 May 2013 	2 	
Item 0006 	10 May 2013 	3 	
Item 0007 	14 May 2013 	16 	
Item 0003 	14 May 2013 	17 	
Item 0008 	15 May 2013 	10 	

As you can see, Item 7 and Item 3 are both on the 14th May, however I'd like one record, summed, with a total of 33 instead of two separate records.

I've read up about the Sum format but that adds all rows together. I've also seen this trick of getting unique values, but it won't work with #ask.

Any help would be greatly appreciated.

IronSwalt (talk)10:10, 19 May 2013


Has no-one solved this problem?

Cheers Walter

IronSwalt (talk)15:23, 8 August 2013

I'm afraid, there's no way to GROUP or SELECT DISTINCT. SMW selects pages (and internal objects). You can only use nested queries: first select dates (and you have to use Array extension or Lua to make selection distinct), format the selection with a template and include a query for Total into the template. Or use Lua from the beginning.

Alexander Mashintalk04:04, 18 August 2014

Like for urls

Hello. The like feature only works for String and Text according to the manual. Is there any way to do something like [[has url::~*blogspot*]] to get all pages which have url to Blogspot domain? Thanks.

Emijrp (talk)09:43, 19 June 2014

A workaround is possible: if you set Has URL property by a template, you can also make the template extract the domain part from the URL and save it as another property, of String type, e.g. Has domain. It will also be faster.

Alexander Mashintalk03:59, 18 August 2014

Problem with Ask query Category:Actor

Hello, I am attempting to upgrade a MediaWiki (1.15.1) and SMW (Version 1.4.3) to the most current version of both MediaWiki and SMW. After the upgrade, everything is working fine except the ASK query with one colon (:), for example. I keep getting zero results when I run any Ask query with one colon. Any help?

Dragonball (talk)23:09, 17 August 2014

What do you mean by "ASK query with one colon (:)"? Will you copy the whole query here?

Alexander Mashintalk03:56, 18 August 2014

How can I sort a table for current's date is displayed?

I tried putting this:

Juan Cristobal Viscarra (talk)05:13, 26 March 2014

How to exclude the current page from the results of a query on the page

For specific are use cases it might be desirable to exclude exactly the one page that contains the query from the set of results of this query. This is currently not a feature of SMW but there are workarounds, for example:

  1. Install Extension:Semantic Extra Special Properties
  2. When following the installation instructions make sure you add the special property for the revision ID, for example by adding the following to LocalSettings.php:
    $sespSpecialProperties[] = '_REVID';// Add property with current revision ID
  3. Wait until Special:SMWAdmin is done
  4. Add [[Revision ID::!{{REVISIONID}}]] to the query string of the inline query
Eric (talk)01:57, 27 February 2013

Selecting pages that have the same value set for a property

On the page for a movie (directed by a director) I would like to display a list of other movies directed by the same director. I.e. other pages in the category:Movies that have the same value set for the property:Directed by.

{{#ask: [[Directed by::{{#show: {{PAGENAME}}| ?Directed by}}]] [[Category:Movies]] |limit=10 |format=datatable }}

The above example produces a datatable with other movies directed by the same director, but it also outputs a warning (caused by the |-sign probably... WARNING: part "" of query not understood, may cause unexpected results...). Is there a better way for doing this?

Regards, Martin

Martinwiss (talk)23:33, 8 October 2012

Try ?Directed by#-.

But I think that querying itself is a bad idea. Better use [[Directed by::{{{Whatever_template_parametre_for_director}}}]].

Alex Mashintalk03:45, 9 October 2012


Martinwiss (talk)17:08, 13 October 2012

What do you mean by {{{Whatever_template_parametre_for_director}}}. Indeed, I have the same request but I don't know how to do.

I have a public proposal linked to Themes. For example, a proposal page :"Give an house to all people" with links to Themes "Human Rights" and "Economy" (property = Proposal-Themes) and I want to see all the other proposals related to the same Themes (in this case "Human Rights" and "Economy").

When I try to list with the primary "ask" as describe by Martinwiss, I get parsing errors like :

The part "|Human Rights" of the query was not understood. Results might not be as expected. The part "," of the query was not understood. Results might not be as expected. The part "|Economy" of the query was not understood. Results might not be as expected. The part "," of the query was not understood. Results might not be as expected. The part "]]" of the query was not understood. Results might not be as expected.

Pbj (talk)11:42, 2 February 2013

Of course, you have to process the parametre before passing it to a query, if it is a list or contains wiki markup. I do it with regular expressions.

Alex Mashintalk15:40, 2 February 2013

Filtering based on the titles of the page

I have a number of pages whose titles are dates, and I would like to filter them to receive pages within a certain date range. The pages don't have any specific property set that is equal to the date in the title. Is there a way to do this with the SMW query language?

Sagittarian (talk)01:36, 25 January 2013

No there isn't.

Jan "Saruman!" S. (talk)06:41, 25 January 2013

Thanks for the reply. I've figured out that I could create a special property along the lines of the SemanticExtraSpecialProperties extension.

Sagittarian (talk)08:24, 25 January 2013