Re: [SMW-devel] {{#ask}}

2007-12-03 Thread cnit
 And another note: {{#ask}} is in SVN (in a first version).
Thank you!

 Working example query:

 {{#ask: [[Category:Country]] [[borders::Nigeria]] |
   ?population|
   ?area#kmĀ² = ''Size''|
   format=list|
   limit = 3|
   link=all|
   intro=bTest/b_|
 }}
It seems that the category specific syntax is identical to ask tag,
parameters of the output are specified without leading questions,
starting with leading question defines the searching property, if I
got it right..

I've tried to convert my SMW 0.7 (really working) query to SMW 1.0RC3
#ask query. But I've stumbled with the problem. There's the query I
use, only the cyrillic property names and format strings are
translated (because it may be confusing to read Cyrillic to
westerners, if there's a need to get original bytecodes, I can send
them with escaped strings):

{{#ask: [[Category:News]] |
?Date|
sort=Date|
order=descending|
limit=3|
format=template|
template=newsrow|
default=There was no news|
searchlabel=Browse all news...|
}}

The results set is correct list of links to the pages where the
property Date is defined, {{{1}}} and {{{2}}} parameter are correctly
expanded in the template, but.. there's no sorting! The results were
sorted by Date field in SMW 0.7, now they aren't.

I've tried to figure out what's wrong, it must be either something had
changed with syntax of the query, or the query is incorrectly parsed.
After browsing through few nested function calls, I've found method
getQueryResult(SMWQuery $query)
in SMW_SQLStore.php, where's the following code:

if ( $smwgQSortingSupport ) {
$order = $query-ascending ? 'ASC' : 'DESC';
if ( ($this-m_sortfield == false)  ($this-m_sortkey 
== false) ) {
$sql_options['ORDER BY'] = 
$pagetable.page_title $order ; // default
} elseif ($this-m_sortfield != false) {
$sql_options['ORDER BY'] = $this-m_sortfield . 
 $order ;
} // else: sortkey given but not found: do not sort
}

My $smwgQSortingSupport is true, of course. But the content of $this
is such:

object(SMWSQLStore)#140 (3) { [m_sortkey:protected]=  string(8) 
\u0414\u0430\u0442\u0430 [m_sortfield:protected]=  bool(false) 
[m_usedtables:protected]=  array(1) { [0]=  string(5) cats1 } }
 translated version:
object(SMWSQLStore)#140 (3) { [m_sortkey:protected]=  string(8)
Date [m_sortfield:protected]=  bool(false) [m_usedtables:protected]=  
array(1) { [0]=  string(5) cats1 } }

You see, that my m_sortkey is proper (Date) - it's not false, but for
some strange reason my m_sortfield is false :-(
The following code in createSQLQuery seems to be designated for
subqueries and not being executed in my case:

if ($sub) {
$nexttables = array();
$nexttables['p' . $tablename] = $table; 
// keep only current table for reference

$this-createSQLQuery($description-getDescription(), $from, $subwhere, $db, 
$nexttables, $nary_pos);
if ($sort) {
$this-m_sortfield = 
$table.$sort;
}
if ( $subwhere != '') {
$where .= ' AND (' . $subwhere 
. ')';
}
}

So, the sql_options ORDER BY is not set..

After that, I've changed the format parameter value to debug,


here's the SQL query it tries to execute:

Generated Wiki-Query
q q+ || 
\u0418\u0437\u043e\u0431\u0440\u0430\u0436\u0435\u043d\u0438\u0435:+/q /q
Query-Size: 3
Query-Depth: 0
SQL-Query
SELECT DISTINCT `page`.page_title as title, `page`.page_namespace as namespace 
FROM `cats3`, `page` INNER JOIN `categorylinks` AS cl2 ON 
cl2.cl_from=`page`.page_id WHERE ((`page`.page_namespace='0') OR 
(`page`.page_namespace='6')) AND (cats3.title=cl2.cl_to)
SQL-Query options
LIMIT=4 OFFSET=0
Errors and Warnings

Auxilliary tables used
cats3: \u041d\u043e\u0432\u043e\u0441\u0442\u0438, 
 translated version:
Generated Wiki-Query
q q+ || Image:+/q /q
Query-Size: 3
Query-Depth: 0
SQL-Query
SELECT DISTINCT `page`.page_title as title, `page`.page_namespace as namespace 
FROM `cats3`, `page` INNER JOIN `categorylinks` AS cl2 ON 
cl2.cl_from=`page`.page_id WHERE ((`page`.page_namespace='0') OR 
(`page`.page_namespace='6')) AND (cats3.title=cl2.cl_to)
SQL-Query options
LIMIT=4 OFFSET=0
Errors and Warnings

Auxilliary tables used
cats3: News,


If you need any additional information to debug, I can provide. The
Property:Date is defined as [[has type::Type:Date]] of course.

I don't know whether it's my simple mistake with query, or a some kind of
bug in SMW..

Re: [SMW-devel] ask query format=template

2007-12-03 Thread Thomas Bleher
* cnit [EMAIL PROTECTED] [2007-12-03 16:24]:
 May I suggest another kind of ask format? Sometimes it's desirable to
 get only a simple count of rows instead of the query result rows. So,
 if there's a 5 rows in the query result, ask format=count would
 return a number 5. It may be useful to statistics, in further
 computations in templates and so on...

format=count already exists, since at least SMW 0.7.

 I really think that SMW requires a better documentation on new
 formats of queries, #ask and subqueries. Because the only
 documentation I've used is outdated:
 http://meta.wikimedia.org/wiki/Help:Substitution
 e.g. no new features, no subqueries here and so on..

??? This page mentions SMW, but it's hardly related to it.
Have you looked at ontoworld.org or http://semantic-mediawiki.org/?

I agree that the wiki pages there need improvement, and hopefully that
will happen once 1.0 is released (personally, I'm currently refraining
from doing any work on the site, because many things have changed
between 0.7 and 1.0 and it's not so easy to separate it; I hope 1.0 will
be released soon, so the old information about 0.7 can be replaced) But
such documentation doesn't write itself. Maybe you can rework the wiki
pages on semantic-mediawiki.org with the things you have already learned
about SMW 1.0.
That would surely be appreciated.

Regards,
Thomas



signature.asc
Description: Digital signature
-
SF.Net email is sponsored by: The Future of Linux Business White Paper
from Novell.  From the desktop to the data center, Linux is going
mainstream.  Let it simplify your IT future.
http://altfarm.mediaplex.com/ad/ck/8857-50307-18918-4___
Semediawiki-devel mailing list
Semediawiki-devel@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/semediawiki-devel