Open main menu

Extension talk:Semantic Compound Queries


Compound Queries in LoopEdit

Been banging my head today trying to get these two extensions to play nice, essentially:

{{#compound_query: {{#forargs: | key | value | [[Category:Genre]] [[{{#var: value}}]];?has_introduction| }} format=table }}

In short, I just want to loop over the query setup and populate it with items from arguments in a template. I'm pretty sure it's a formatting issue that's tripping it up. If I strip everything back to without the loop:

{{#compound_query: [[Category:Genre]] [[Trap]];?has_introduction| [[Category:Genre]] [[Dubstep]];?has_introduction| format=table }}

Then it all works perfectly fine.

I doubt that's possible... you might have better luck using Scribunto for something like that. Yaron Koren (talk) 15:19, 18 April 2013 (UTC)
Ah, thanks for the tip! Rodeoclash (talk) 21:34, 18 April 2013 (UTC)

Export to CSVEdit

Hello, does Compound Query have ability to export to CSV? I tried "format=csv", but it does not work, while it works for regular queries. Version 0.3.2. Patelmm79 (talk) 20:26, 5 November 2012 (UTC)

What version of Semantic MediaWiki are you using? Yaron Koren (talk) 04:00, 6 November 2012 (UTC)

SMW breaks SCQ in MW 1.13.4Edit

SMW does not fully opperate correctly with MW 1.13.4. The only thing that I have found breaks is Semantic Compound Queries. It works great with MW 1.14


Hi - what's the error message you get? Yaron Koren 18:20, 29 June 2010 (UTC)
It will not show the results of any part of the query except for the final query. Hard to explain. Simple example below.
{{#compound_query: [[Category:Music Events]][[Has Date::{{#calendarstartdate:}}]][[Has Date::{{#calendarenddate:}}]]
;?Has Date;color=red;limit=500
|[[Category:Corporate Meetings]][[Has Date::{{#calendarstartdate:}}]][[Has Date::{{#calendarenddate:}}]]
;?Has Date;color=blue;limit=500
|[[Category:Marketing Events]][[Has Date::{{#calendarstartdate:}}]][[Has Date::{{#calendarenddate:}}]]
;?Has Date;color=green;limit=500
In this example the output would only show the Marketing Events. Also, "color" do not work, but I have been using a template to get around that.


Oh. Well, I'm guessing that this will be hard to debug - I should probably just change the SCQ documentation to say that it requires version 1.14 or later of MW. Yaron Koren 22:02, 29 June 2010 (UTC)
It is not the relationship between MW 1.13.4 and is between MW 1.13.4 and SMW SCQ is the only thing that I have found that breaks. When I rolled back to SMW 1.4.3 it worked fine again. So, the SMW page needs to be changed to be compatible with MW 1.14.x and newer. --Dgennaro 13:37, 30 June 2010 (UTC)
But the latest SMW, by itself, works correctly with MW 1.13, no? Yaron Koren 15:50, 30 June 2010 (UTC)
Yes, SCQ is the only thing that I have found so far that fails. --Dgennaro 15:51, 30 June 2010 (UTC)

Similar Problem to above, only final query showingEdit

I have found a similar problem within my wiki I have the following code:

{{#compound_query:[[Category:Band]] [[Postcode::{{PAGENAME}}]]; ?Bandroom Location; icon=Tuba Small.png;
|[[Category:Venue]] [[Venue Postcode::{{PAGENAME}}]]; ?Venue Location; icon=Venue.png;

All it is displaying is the final query.

I have the following setup

  • MediaWiki 1.16.0
  • PHP 5.2.13 (cgi)
  • MySQL 4.1.22-standard-log
  • Semantic Compound Queries (Version 0.2.6)
  • Semantic Forms (Version 2.0.1)
  • Semantic Maps (Version 0.6.6)
  • Semantic MediaWiki (Version 1.5.2)
  • Admin Links (Version 0.1.3)
  • Header Tabs (Version 0.7)
  • Hide Empty Sections (Version 1.0)
  • Maps (Version 0.6.6)
  • ParserFunctions (Version 1.3.0)
  • FCKeditor (Version fckeditor/mw-extension $Rev$ 2008)
  • Semantic Forms Input Types (Version 0.2)
  • Semantic Result Formats (Version 1.5.0)
  • Validator (Version 0.3.6 rc1)
Well, you only have two queries - are you sure that the first one works, by itself? And what happens if you change to a simpler format, like "table"? Yaron Koren 15:15, 30 September 2010 (UTC)
Many thanks. They both worked by themselves. But changing it to table shown me that the co-ordinates weren't showing up for one of them and it pushed me in the right direction. Thanks again Yaron !!

Undefined PropertyEdit

Notice: Undefined property: SMWQueryResult::$display_options in /var/www/pcwiki/extensions/SemanticCompoundQueries/SCQ_QueryResult.php on line 27 any clue why this would be outputting like this? --Willjermuk 20:12, 10 September 2010 (UTC)

Cannot count pages with specific valuesEdit

Hi, I want to count the associated pages where a specific value is set and show them in a piechart. In detail:

{{#vardefine:gruen| [[aktueller Status::Grün]] [[-Hat Teil::{{SUBJECTPAGENAME}}]] 
; mainlabel=Teile
; ?Aktueller Status
; format=count

{{#vardefine:gelb| [[aktueller Status::Gelb]] [[-Hat Teil::{{SUBJECTPAGENAME}}]] 
; mainlabel=Teile
; ?Aktueller Status
; format=count

{{#vardefine:rot| [[aktueller Status::Rot]] [[-Hat Teil::{{SUBJECTPAGENAME}}]] 
; mainlabel=Teile
; ?Aktueller Status
; format=count

{{#compound_query:{{#var:rot}} | {{#var:gelb}} | {{#var:gruen}} | format=table}}

And the following error occurs:

Warning: Attempt to assign property of non-object in C:\<wikipath>\mediawiki\extensions\SemanticCompoundQueries\SCQ_QueryProcessor.php on line 131

Warning: Attempt to assign property of non-object in C:\<wikipath>\mediawiki\extensions\SemanticCompoundQueries\SCQ_QueryProcessor.php on line 131

Fatal error: Call to a member function getPrintRequests() on a non-object in C:\<wikipath>\mediawiki\extensions\SemanticCompoundQueries\SCQ_QueryProcessor.php on line 62

BTW: without the parser-functions #var and #vardefine in an all-in-one-query it doesn't work, too. Each single one of the 3 queries work fine! But I want the result in only one table or pie-chart... Hmm, or is there any other possibility to run such a query?!

Semantic Compound Queries with timelineEdit

Hi, (first of all, sorry for my english) Can I use a a timeline as format of a query?

I can make an #ask query only for a category, but I like to print in a single timeline all the events which are related to different categories.

Something like this:

{{#compound_query: [[RiguardaProgettoCantiere::{{PAGENAME}}]] ; ?HaDataInizioCantiere ; ?HaFineCantiere   
|  [[HaOggettorifFonte::{{PAGENAME}}]]; ?HaDataFonte
| format=timeline}}

--Feedmyego 18:42, 18 November 2010 (UTC)

Hi - I think that should work, but I've never tried it with timeline, so I don't know for sure. Feel free to try it out. Yaron Koren 21:34, 18 November 2010 (UTC)
It doesn't work, but i'm not a master in mediawiki coding, so I don't know if it's a SRF problem, or an error in my query. If anyone succeeds, let me know :) --Feedmyego 16:48, 21 November 2010 (UTC)

I'm sure the code is very different for both Compound Queries and SRF/Timeline since this discussion topic was raised, but for what it's worth the following does work on my load (MW 1.20.4, SMW, SF 2.5.2, PHP 5.4.7):
  [[Category:Mission]] [[Mission type::ISS Increment]] [[Start date::+]];
    ?Start date;
    ?End date;
| [[Category:Mission]] [[Vehicle::Soyuz]] [[Start date::+]];
    ?Start date;
    ?End date;
| sort=Start date
| order=descending
| format=timeline
| timelinebands=MONTH,YEAR
| timelineposition=today
| timelinesize=360px
| limit=150
Also, I'm currently tweaking SRF/Timeline to allow you to choose the color of event bands on the timeline. I have it working without compound queries. So this works:
{{#ask: [[Category:Mission]] [[Start date::+]]
| ?Start date = start
| ?End date = end
| sort=Start date
| order=descending
| format=timeline
| timelinebands=MONTH,YEAR
| timelineposition=today
| timelinesize=360px
| durationcolor=green
| limit=150
But with Compound Queries it does not work (see next code block). Note the inclusion of "durationcolor" parameter, which is not available in the current version of Timeline. This will color all the bands green in the above query.
  [[Category:Mission]] [[Mission type::ISS Increment]] [[Start date::+]];
    ?Start date;
    ?End date;
| [[Category:Mission]] [[Vehicle::Soyuz]] [[Start date::+]];
    ?Start date;
    ?End date;
| sort=Start date
| order=descending
| format=timeline
| timelinebands=MONTH,YEAR
| timelineposition=today
| timelinesize=360px
| limit=150
Doing the compound query above does not give me green or orange bands. It gives the default red. Is there something special that has to be done within an extension attempting to use Compound Queries to make the extension able to pass different parameters for each sub-query? Do I have to make that "durationcolor" parameter special in some way for it to be recognized? Thanks! FYI, I will be posting a similar question on the Timeline Format talk page eventually, which will include the changes I made to be able to change event band color.
--Jamesmontalvo3 (talk) 22:04, 8 May 2013 (UTC)

Problem with more than one compound queryEdit

When I create more than one compound query on a page, the maps stops working

Right now there's only one, to show that works ok. But stops if you duplicate:

{{#compound_query: Categoria:Restaurantes Bairro::Ipanema; ?LatLong;

   | format=googlemaps
   | height=250
   | width=100%
   | autozoom=off


Hi, I don't understand - where's an example of a compound query that's not working? Yaron Koren 15:40, 2 March 2011 (UTC)
Hi Yaron,
It works fine if I use compound_query only once on the artile.
Okay, I see the problem - I'm guessing that this is an issue with Semantic Maps. Yaron Koren 18:50, 2 March 2011 (UTC)

incomplet result w/ [SCQ] in comparison to regular #ask ?Edit

hi i have this query compared to each other with two different result. the compound query has less result compared to the the regular ask syntax query. Even after a property updates the result still unchanged

{{#compound_query:[[Category:WO]][[WO status::closed]];?WO due date


{{#ask:[[Category:WO]][[WO status::closed]]|?WO due date

any thoughts?

--Msevero 09:04, 31 March 2011 (UTC)

No idea. Yaron Koren 12:05, 31 March 2011 (UTC)
thanks for the reply, --Msevero 23:00, 1 April 2011 (UTC)


I just noticed that the combination "limit=0" and "searchlabel=foo", as used sometimes in regular inline queries, does not work in SCQ. I think that would be worth considering as an option in future releases. Cavila 11:43, 19 May 2011 (UTC)

sorting of result format broadtableEdit

Hi, is it possible to sort the queried results somehow? So far it shows the results are printed in ascending order but to have this in a descending order would be cool too. The regular printout statements do not seem to work.

| headers=show
| format=broadtable
| sort=property name
| order=descending

Hmm ... Cheers --[[kgh]] 13:56, 15 August 2011 (UTC)

sql error after updateEdit

i have updated semantic compound queries from 0.2.7 to 0.2.8 and my query crashed. {{#compound_query: Kategoria:Wydarzenia; [[Rozpoczęcie::>{{#calendarstartdate:}}]]; [[Rozpoczęcie::<{{#calendarenddate:}}]]; ? Rozpoczęcie; color=#dd0000; limit=1500 |format=calendar}}

error: SMWSQLStore2::getSMWPageIDandSort”. database error „1054: Unknown column 'smw_subobject' in 'where clause' (localhost)”.

What version of SMW are you using? Yaron Koren 15:11, 17 August 2011 (UTC)

smw 1.6, semantic result formats 1.6, validator 0.4.9

Ah - you should comment out the other SMW-based extensions in LocalSettings.php (other than SMW), then go to Special:SMWAdmin and click the "initialise/upgrade DB" button, then uncomment the extensions. Yaron Koren 16:28, 18 August 2011 (UTC)

works now,thank you


Heiya, there may I download the new version? Cheers --[[kgh]] 18:06, 4 October 2011 (UTC)

I actually wanted to skip to the next version, since 0.2.10 had problems with the latest SMW. Thanks for the reminder - I just released the latest version, 0.3, where hopefully all the problems are fixed. Yaron Koren 19:41, 4 October 2011 (UTC)
Ah, I see. I just stumbled over this for another reason. The new version makes me curious regarding the sorting issue I discovered. This one sounds like a fix for it which should be very cool then. Cheers --[[kgh]] 19:48, 4 October 2011 (UTC)


I get: Fatal error: Cannot call method self::compareQueryResults() or method does not exist in /home/wikirio/public_html/extensions/SemanticCompoundQueries/SCQ_QueryProcessor.php on line 77 I had to return to the previous version

I was updating to see if the new version is fixing this old issue. The compound queries doesnt work when you select 2 in the same page:


Hi - this might be an issue due to your PHP version. Could you try restoring SCQ back to the newest version, then changing line 77 from
                uasort( $results, 'self::compareQueryResults' );
                uasort( $results, array( 'SCQQueryProcessor', 'compareQueryResults' ) );
...and see if that fixes it? Yaron Koren 18:56, 13 November 2011 (UTC)
Yaron, works fine now. Thanks! Do you know what might be the issue I have when I use two Coumpound Queries on the same page? Regards, Edgard
Cool. I don't know - it looks like the issue is coming from Semantic Maps. Yaron Koren 20:21, 13 November 2011 (UTC)
Awn... Works fine when I use ASK two times. Doesnt work only for Compound Query :(
Yeah, but what if you use two non-map compound queries? Yaron Koren 20:44, 13 November 2011 (UTC)
Did you guys ever get to the bottom of the error message above? I have working SMW/SM maps all over my site and downloaded 0.3 to try and get maps with different icons. Trying to recreate a (working) #ask function as a compound gave the same exception as the above. Any clues as to what I can check? I am pretty happy that all my ordinary #ask queries are fine. Thanks - and kudos for some great tools, Tim D
BTW the fix above instantly fixed the issue for me - but are there any side effects of the edit to that code? - Tim D

Cool - no, I doubt there are any side effects to it; it's just syntax that seems to work across more versions of PHP. Yaron Koren 20:20, 28 November 2011 (UTC)

Sorting results?Edit

Are the parameters for sorting different from those in regular #ask queries? They don't seem to work here. Cavila MW 1.19.2, MySQL 5.1.66, Php 5.3.3-7, SMW 1.8, SF 1.5.1 22:43, 12 February 2013 (UTC)

They should work... I don't fully remember, but I think you apply those to the overall query, not the subquery. The property/printout names should be the same for each subquery, though. Yaron Koren (talk) 03:30, 13 February 2013 (UTC)
Yes, I know, that's why I was somewhat surprised. Maybe it's because I was not querying pages, but subobjects, on the basis of an inverse "Has subobject" property. Is sorting of subobjects supported in compound queries? Cavila MW 1.19.2, MySQL 5.1.66, Php 5.3.3-7, SMW 1.8, SF 1.5.1 22:51, 14 February 2013 (UTC)
If it's supported in regular queries, it should work in #compound_query. Whether it's supported in regular queries, though, I don't know. Yaron Koren (talk) 01:52, 15 February 2013 (UTC)
The "sort" parameter works fine in regular #ask-queries on subobjects, but not in SCQ, I'm afraid. On a more general note, the documentation does not currently make clear if the parameters for regular queries can also be used in compound queries (not to mention those that come with SRF). For instance, "limit" and "searchlabel" do not appear to be available (in fact, a "further results" link is missing altogether). Cavila
MW 1.19.2, MySQL 5.1.66, Php 5.3.3-7, SMW 1.8, SF 1.5.1
16:56, 15 February 2013 (UTC) (yes, what a hideous signature - I'm looking for a less obtrusive way to do this)
I do not think that sorting is possible (see my post of 2011) or at least I have not managed to do it so far. Cheers --[[kgh]] (talk) 10:39, 24 May 2013 (UTC)

Compound query with template in calendar formatEdit

Hi Yaron,

Doesn't the compound query work with template in calendar format? When I remove the template the retrieved values appear in a calendar, but with the template they end up in a table format. With a 'ask' in stead of compound query it shows the way it should in calendar format.


That sounds like a bug - is this problem viewable somewhere? Yaron Koren (talk) 22:41, 10 March 2013 (UTC)

How to increase the maximum of results displayed on a map ?Edit

Thanks Nicolas NALLET (talk) 21:14, 9 April 2013 (UTC)

Use the "limit=" parameter. Yaron Koren (talk) 21:57, 9 April 2013 (UTC)
Hi, the limit doesnt have an impact, It s a compound query on internal object (around 2700 stored in the same page) with geographic coordinates... The aim is to diplay it on a map.

See here

Ah - with that number of results, you might need to use $smwgQMaxInlineLimit. However, another possible solution is to use the "cluster" option for maps - though I don't know well it would work with SCQ. Yaron Koren (talk) 12:28, 10 April 2013 (UTC)

format=csv not workingEdit

Lsilverman (talk) 23:39, 4 February 2014 (UTC)

Versions: Compound Queries 0.3.4, MW 1.22.2 and SMW

format=csv and format=dsv don't work.

broadtable works, table works. Haven't tried others.

My example:

{{#compound_query:[[Category:Client]] [[Has paid module::{{{module}}}]]
|[[Category:Client]] [[Has unpaid module::{{{module}}}]]

loops and imagesEdit

Hi, I am new to Semantic. I have been trying to build a basic query that will list all items in a category and their properties :

{{#ask:[[Category:items]] [[name::+]] [[size::+]] 
| ?name
| ?size#-
| ?stacklimit#-
<!-- ... -->
| ?location
| ?description#-
| mainlabel=-
| headers=plain

And I keep getting several repeated over and over again, receiving some 500 items for what should have been 20. Can you point me in the right way to solve this?

Also what is the right way to list all image files in a category. I have tried using this:

{{#ask:[[Category:items images]]
| format=ul

But I get a list of thumbnails and change it plain, result in a plain list of names. How can I get a list of name + links?

Thanks -- 00:25, 9 November 2014 (UTC)

I believe you're asking in the wrong place - #ask is part of the core Semantic MediaWiki extension, while Semantic Compound Queries is a separate spinoff extension. Yaron Koren (talk) 16:00, 9 November 2014 (UTC)

SCQ and template parameterEdit

I tried to use SCQ 0.4 with SRF calendar together with a template for formatting the calendar entries:

{{#compound_query:[[Category:Day Off Request]][[Has Requester::{{FULLPAGENAME}}]]; ?Day_Off_Date; ?Has_Requester
   |[[Category:Sprint]]; ?Start_Date; ?Sprint_ID

This works fine for Day Off Requests but not for Sprints. Sprints will be shown as [[SPR00008|]]. So the template seems to be used only for the first query.

Template:SrfDayOffRequest is a simple


I also tried the following without success:

{{#compound_query:[[Category:Day Off Request]][[Has Requester::{{FULLPAGENAME}}]]; ?Day_Off_Date; ?Has_Requester; template=SrfDayOffRequest
   |[[Category:Sprint]]; ?Start_Date; ?Sprint_ID; template=SrfDayOffRequest

--Planetenxin (talk) 11:15, 28 July 2015 (UTC)

Order of output based on order of sub queries?Edit

I was sort of hoping I could use the SCQ to order my output based on specific property values. Based on that subsequent subqueries will not return an earlier retrieved result. E.g. the following query would return a table with pages from category records with prop=A before prop=B and any pages with prop not being either A or B as last. I am seeing random order in the overall result, is there a way to set deterministically the sequence of the pages in the resulting table?


PeterBodifee (talk) 14:59, 28 November 2016 (UTC)

I think just adding "|sort=prop" after "|format=table" would fix the problem. Maybe the documentation should mention that explicitly. Yaron Koren (talk) 16:56, 28 November 2016 (UTC)
Unfortunately it doesn't make any difference in the output. Closer inspection of the produced table shows the sort order is the pagename. And to be clear I don't want the table to be sorted on values of prop, I want the results from the first sub query first, then the results from the second sub query (not repeating any pages which already are returned by the first sub query), and so on. PeterBodifee (talk) 18:06, 28 November 2016 (UTC)
Oh, I get it. I'm surprised that the initial #compound_query call doesn't display the results in that order; but it's been a while since I looked into it. One hack you could do is, assuming all these pages get their values stored with the same template, have the template set a 2nd property, called "Sorting prop" or something, that gets set to 1 if prop is A, 2 if prop is B, and 3 if it's anything else - you could do that with a call to #switch. Then you would just need a regular #ask query, sorting on "Sorting prop". Yaron Koren (talk) 18:15, 28 November 2016 (UTC)
Thanks for the suggestion. But that is not going to work for me. First I am going to query multiple categories using [[Category:cat1||cat2||cat3]] , however the structure of the templates in all these categories are the same. However that is not the real challenge. The query is going to be parameter driven, passing on a prioritized set of values for prop (and some other properties with specific value arrays as well - why easy when we can do something advanced ;-) , so I don't know in advance what the user of this query will use as values. For our purpose we want a deterministic result of the order (1st subquery #1, 2nd subquery #2, etc), so we can apply meaning to the order (the results are architecture compliance rules where the priority is based on the order of a prioritized set of values for prop). In one template call it could be F, D and in a next call it could be E, A, H (up to 5 values for 5 sub queries). From observation it looks like that all sub query results are combined and then sorted on pagename. The workaround I can think of now is to create tables per sub query (which I could do with regular #ask), the disadvantage is that given the values for the properties on our pages (they are all arrays!), we would repeat results over the multiple tables and I would really like to avoid repetition (which attracted me to use SCQ). PeterBodifee (talk) 18:55, 28 November 2016 (UTC)

how to install in 1.25.* or newerEdit

I just installed mw 1.28. I installed SCQ using Composer. However it does not show up in the version list. I tried to load with with "require_once" as instructed. As of version 1.25 the loading with "require_once" is replaced by wfLoadExtension. Then I tried to use that. But that results in an error: extension.json is missing.

How do I get it loaded?

thanks. Michiel

This extension is broken for MW 1.28 I'm afraid. Up to MW 1.27 you have to use version 0.4.1 and invoke it the classic way since version 1.0.0 is not working. I will file a bug for this. Cheers --[[kgh]] (talk) 00:19, 20 December 2016 (UTC)
Now filed as issue 22 --[[kgh]] (talk) 00:40, 20 December 2016 (UTC)
This has been fixed now with version 1.0.1 so you should be able to install the extension using Composer. --[[kgh]] (talk) 08:02, 21 December 2016 (UTC)

Restrict the result on each queryEdit

Place1::Place A1 Place2::Place B1
PlaceName1::City PlaceName2::Kitchen
PlaceName1::Mountain PlaceName2::Bedroom
PlaceName1::Lake PlaceName2::Bathroom
Place1::Place C1 Place2::Place D1
PlaceName1::Livingroom PlaceName2::Big City
PlaceName1::Diningroom PlaceName2::Village
PlaceName1::Bedroom PlaceName2::Farm

{{#compound_query: [[PlaceName1::Bedroom]];?Place1 | [[PlaceName2::Bedroom]];?Place2 |format=valuerank }}


Place A1, Place B1, Place C1, Place D1


I'd like to see only Place B1 and Place C1 in the results. is it possible?

Return to "Semantic Compound Queries" page.