Page MenuHomePhabricator

the ~ "like" comparator doesn't work for many-valued properties
Closed, ResolvedPublic

Description

Author: info

Description:
Even if you enable the ~ comparator in $smwgQComparators in SMW_Settings.php,
querying a many-valued property for ~*partial* doesn't work.

For example, using ontoworld.org's [[Property:Employment]] and [[Einstein]] article

[[Employment::?;~?atent*;?;?]]

doesn't find Einstein's "patent examiner" job.

The reason this doesn't work is that SMW_DV_NAry.php's prepareValue method doesn't match SMW_QueryProcessor.php's prepareValue method. The latter compares $smwgQComparators and checks for case '~', the former hardcodes.

After copying code, the above example works in SMW 1.0.

Ideally the common code should be in a common function, but at least the code in each place should comment

// The same code is in SMW_DV_NAry.php's prepareValue()

and vice-versa.


Version: unspecified
Severity: normal

Details

Reference
bz13479

Event Timeline

bzimport raised the priority of this task from to Medium.Nov 21 2014, 10:02 PM
bzimport set Reference to bz13479.

info wrote:

Here's the "copying code" fix.

Index: C:/xampplite/htdocs/mediawiki/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php

  • C:/xampplite/htdocs/mediawiki/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (revision 33658)

+++ C:/xampplite/htdocs/mediawiki/extensions/SemanticMediaWiki/includes/SMW_DV_NAry.php (working copy)
@@ -323,6 +323,7 @@

	}

	private function prepareValue(&$value, &$comparator, &$printmodifier) {

+ global $smwgQComparators;

		// get print modifier behind *
		$list = preg_split('/^\*/',$value,2);
		if (count($list) == 2) { //hit

@@ -335,6 +336,7 @@

			return;
		}
		$list = preg_split('/^(<|>|!)/',$value, 2, PREG_SPLIT_DELIM_CAPTURE);

+ $list = preg_split('/^(' . $smwgQComparators . ')/',$value, 2, PREG_SPLIT_DELIM_CAPTURE);

		$comparator = SMW_CMP_EQ;
		if (count($list) == 3) { // initial comparator found ($list[1] should be empty)
			switch ($list[1]) {

@@ -350,8 +352,13 @@

					$comparator = SMW_CMP_NEQ;
					$value = $list[2];
				break;

+ // The same code is in SMW_QueryProcessor.php's prepareValue()
+ case '~':
+ $comparator = SMW_CMP_LIKE;
+ $value = $list[2];
+ break;

				//default: not possible
			}
		}
	}

@@ -417,5 +424,15 @@

		return; // not implemented yet
	}

+ protected function getServiceLinkParams() {
+ Simply concatenate each type's service link params.
+ $slps = array();
+ foreach ($this->m_values as $value) {
+
I just want to append, PHP's array behavior is awful.
+ $slps = array_merge($slps, $value->getServiceLinkParams());
+ }
+ return $slps;
+ }
+
}

I now have made the function in SMWQueryParser static, so it can directly be called from the n-ary datavalue implementation.