Page MenuHomePhabricator

[patch] LIKE queries with spaces in search term broken for Page properties in SMW 1.6+
Closed, ResolvedPublic

Description

Author: andrew.daugherity+wikibugs

Description:
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...


Version: unspecified
Severity: normal

attachment smw-like-spaces-fix-17.diff ignored as obsolete

Details

Reference
bz34665

Event Timeline

bzimport raised the priority of this task from to Needs Triage.Nov 22 2014, 12:11 AM
bzimport set Reference to bz34665.
bzimport added a subscriber: Unknown Object (MLST).

Thanks for the patch Andrew!

Markus, can you have a look at this one?

Markus: Can you please review the patch and afterwards replace the "patch-need-review" keyword by "patch-reviewed"?

bugzilla wrote:

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.

andrew.daugherity+wikibugs wrote:

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!

andrew.daugherity+wikibugs wrote:

fix like queries for type Page

Attached:

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.