https://bugzilla.wikimedia.org/show_bug.cgi?id=34665

       Web browser: ---
             Bug #: 34665
           Summary: [patch] LIKE queries with spaces in search term broken
                    for Page properties in SMW 1.6+
           Product: MediaWiki extensions
           Version: any
          Platform: All
        OS/Version: All
            Status: NEW
          Severity: normal
          Priority: Unprioritized
         Component: Semantic MediaWiki
        AssignedTo: [email protected]
        ReportedBy: [email protected]
                CC: [email protected], [email protected]
    Classification: Unclassified
   Mobile Platform: ---


Created attachment 10083
  --> https://bugzilla.wikimedia.org/attachment.cgi?id=10083
fix like queries on page-type properties

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

-- 
Configure bugmail: https://bugzilla.wikimedia.org/userprefs.cgi?tab=email
------- You are receiving this mail because: -------
You are the assignee for the bug.
You are on the CC list for the bug.

_______________________________________________
Wikibugs-l mailing list
[email protected]
https://lists.wikimedia.org/mailman/listinfo/wikibugs-l

Reply via email to