SandboxQuery

aus www.kruedewagen.de, Homepage von Ralf und Judith Krüdewagen (Kruedewagen)
Zur Navigation springen Zur Suche springen

This sample page with semantic queries shows if and how a sort parameter affects the output of an inline query. If you sort by a "wrong" property, than the result set is changed. See [1] and [2].

Query all pages in category

This query finds all pages in the category, even if one of the pages does not contain a property from the given columns.

{{#ask: [[Category:Testing]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|order=ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxBA2
SandboxCA3B3

Query all pages in category sorted by property A

This query returns all pages in the category sorted by property A. Since page SandboxA, SandboxB and SandboxC do contain the property A, all of them are returned.

{{#ask: [[Category:Testing]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property A
|order=ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxBA2
SandboxCA3B3

Query all pages in category sorted by property B

But the main goal is to explicitly sort by property B. All pages in the category shall be found in the same way as before, even pages having property B not set.

But since page SandboxB does not contain the property B, it is not in the result.

{{#ask: [[Category:Testing]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property B
|order=ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Set property within the ask condition

Setting the property B within the ask condition even just return pages with this property set:

{{#ask: [[Category:Testing]][[Has property B::+]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property B
|order=ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Well, just removing the sort does not change the result set:

{{#ask: [[Category:Testing]][[Has property B::+]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Some variations

Another try:

{{#ask: [[Category:Testing]][[Has property A::+]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property B
|order=ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Another try:

{{#ask: [[Category:Testing]][[Has property B::+]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property B,Has property A
|order=ASC,ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Another try:

{{#ask: [[Category:Testing]][[Has property B::+]]
|?Has property A=Property A
|?Has property B=Property B
|offset=0
|limit=30
|format=table
|mainlabel=Page
|sort=Has property A,Has property B
|order=ASC,ASC
}}
PageProperty AProperty B
SandboxAA1B1
SandboxCA3B3

Conclusion

Never use a property as sort value, which is not set on all pages you want to return. When using a form make those fields mandatory you want to sort by later.

References