Last modified: 2014-09-23 19:59:46 UTC

Wikimedia Bugzilla is closed!

Wikimedia migrated from Bugzilla to Phabricator. Bug reports are handled in Wikimedia Phabricator.
This static website is read-only and for historical purposes. It is not possible to log in and except for displaying bug reports and their history, links might be broken. See T36665, the corresponding Phabricator task for complete and up-to-date bug report information.
Bug 34665 - [patch] LIKE queries with spaces in search term broken for Page properties in SMW 1.6+
[patch] LIKE queries with spaces in search term broken for Page properties in...
Status: NEW
Product: MediaWiki extensions
Classification: Unclassified
Semantic MediaWiki (Other open bugs)
unspecified
All All
: Unprioritized normal with 1 vote (vote)
: ---
Assigned To: Nobody - You can work on this!
: patch, patch-need-review
Depends on:
Blocks:
  Show dependency treegraph
 
Reported: 2012-02-24 01:21 UTC by Andrew Daugherity
Modified: 2014-09-23 19:59 UTC (History)
4 users (show)

See Also:
Web browser: ---
Mobile Platform: ---
Assignee Huggle Beta Tester: ---


Attachments
fix like queries on page-type properties (SMW 1.7) (1.22 KB, patch)
2012-02-24 01:21 UTC, Andrew Daugherity
Details
fix like queries for type Page (2.70 KB, patch)
2013-06-17 22:24 UTC, Andrew Daugherity
Details

Description Andrew Daugherity 2012-02-24 01:21:06 UTC
Created attachment 10083 [details]
fix like queries on page-type properties (SMW 1.7)

After upgrading my SMW installation I discovered than many of my "List" pages with built-in semantic queries (many of which are templates using {{PAGENAME}} as the search term) no longer returned any results.  I finally tracked it down -- queries are broken when all of the following are true:
* queries using LIKE (e.g. [[property::~foo*]])
* on properties of type Page
* the search term contains a space

Using format=debug with my queries and comparing the generated queries between SMW 1.5.6 (which I have been using, and does not have this problem), 1.6.2, and 1.7.0.2 (after database reloads and SMW_setup/refreshData, of course), I found the problem: spaces in the query string are converted to underscores, which then get escaped further.

In SMW 1.5.6 the WHERE condition of the generate query was:
  t5.smw_sortkey LIKE 'SLES 11%' (works great!)
but in 1.6+ it is instead:
  t5.smw_sortkey LIKE 'SLES\\_11%' (no rows returned).

Alternatively,
  t5.smw_title LIKE 'SLES\\_11%'
works also, but it wasn't obvious to me how to achieve that in the code.

I patched in a quick hack to compileQueries() (see attached diff) that replaces '_' with ' ' in $value for LIKE queries on WikiPage objects, and now everything is back to normal.  It's an ugly hack but it gets the job done, and I haven't been able to find any breakage caused by it, including string properties containing underscores (page titles can never contain unescaped underscores, so that isn't a concern).

And to head off the inevitable objections:

Yes, I know the documentation says LIKE queries are only supported on properties of type String.  Nevertheless,
(a) There is a whole section of code (the one I've patched) handling LIKE queries for Page properties
(b) It worked fine in 1.5.6
(c) It still works (without my patch) as long as the search term doesn't contain a space.

I'm sure there's a better way to accomplish this using the defined API, but I'll leave that to an actual PHP programmer.  Feel free to come up with a better solution...
Comment 1 Jeroen De Dauw 2012-02-24 22:53:39 UTC
Thanks for the patch Andrew!

Markus, can you have a look at this one?
Comment 2 Andre Klapper 2012-05-08 09:10:49 UTC
Markus: Can you please review the patch and afterwards replace the "patch-need-review" keyword by "patch-reviewed"?
Comment 3 bugzilla 2013-04-03 15:19:49 UTC
I've had very similar issues.  A quick fix without patching is to replace the space with a "?".  Search continues as normal.  Thanks for fixing!


Works using "like" feature on a property that has a type of page.
[[Incentive/Type::~*Portfolio*]]
http://en.openei.org/w/index.php?title=Special%3AAsk&q=%5B%5BIncentive%2FType%3A%3A~*Portfolio*%5D%5D&po=%3FIncentive%2FType&eq=yes&p%5Bformat%5D=broadtable&sort_num=&order_num=ASC&p%5Blimit%5D=&p%5Boffset%5D=&p%5Blink%5D=all&p%5Bsort%5D=&p%5Bheaders%5D=show&p%5Bmainlabel%5D=&p%5Bintro%5D=&p%5Boutro%5D=&p%5Bsearchlabel%5D=%E2%80%A6+further+results&p%5Bdefault%5D=&p%5Bclass%5D=sortable+wikitable+smwtable&eq=yes

Doesn't work due to space (however, documentation has a two-word entity with space in between)
[[Incentive/Type::~*Portfolio Standard*]]
http://en.openei.org/w/index.php?title=Special%3AAsk&q=%5B%5BIncentive%2FType%3A%3A~*Portfolio+Standard*%5D%5D&po=%3FIncentive%2FType%0D%0A&eq=yes&p%5Bformat%5D=broadtable&sort_num=&order_num=ASC&p%5Blimit%5D=&p%5Boffset%5D=&p%5Blink%5D=all&p%5Bsort%5D=&p%5Bheaders%5D=show&p%5Bmainlabel%5D=&p%5Bintro%5D=&p%5Boutro%5D=&p%5Bsearchlabel%5D=%E2%80%A6+further+results&p%5Bdefault%5D=&p%5Bclass%5D=sortable+wikitable+smwtable&eq=yes

Works by replacing space with a ?:
[[Incentive/Type::~*Portfolio?Standard*]]
http://en.openei.org/w/index.php?title=Special%3AAsk&q=%5B%5BIncentive%2FType%3A%3A~*Portfolio%3FStandard*%5D%5D&po=%3FIncentive%2FType%0D%0A&eq=yes&p%5Bformat%5D=broadtable&sort_num=&order_num=ASC&p%5Blimit%5D=&p%5Boffset%5D=&p%5Blink%5D=all&p%5Bsort%5D=&p%5Bheaders%5D=show&p%5Bmainlabel%5D=&p%5Bintro%5D=&p%5Boutro%5D=&p%5Bsearchlabel%5D=%E2%80%A6+further+results&p%5Bdefault%5D=&p%5Bclass%5D=sortable+wikitable+smwtable&eq=yes

I haven't looked into the code, but I figured it'd be a simple fix if you knew the bug existed.
Comment 4 Andrew Daugherity 2013-06-17 22:21:25 UTC
That's great for your usage, but doesn't help if you're using templates which use {{PAGENAME}} as a query term, as I am.

I have adapted the patch for SMW 1.8.x & SQLStore3 and will attach the updated patch to this bug.  Can someone please look at this and approve it, or, if there's a better solution, enlighten us?

Thanks!
Comment 5 Andrew Daugherity 2013-06-17 22:24:42 UTC
Created attachment 12567 [details]
fix like queries for type Page
Comment 6 Jeroen De Dauw 2013-07-23 09:32:34 UTC
Hey Andrew, thanks for your patch. I'm unfortunately not familiar enough with this code to tell if this will not cause other problems without digging into it a lot further. Hopefully Markus can have a look.

Note You need to log in before you can comment on or make changes to this bug.


Navigation
Links