tetherless-world / s2s

Tetherless World S2S Faceted/Hierarchical Browser
GNU General Public License v2.0
1 stars 0 forks source link

getQueryConstraints() method in config.php has query issue #5

Closed nahgnaw closed 9 years ago

nahgnaw commented 9 years ago

In the getQueryConstraints() in config.php, the constraint clause for each $constraint_type shouldn't be in conjunction.

The code should be something like this:

public function getQueryConstraints(array $constraints) {   

    $body = "";     
    foreach($constraints as $constraint_type => $constraint_values) {           
        $arr = array(); 
        foreach($constraint_values as $i => $constraint_value) {
            $constraint_clause = $this->getQueryConstraint($constraint_type, $constraint_value);
            array_push($arr, $constraint_clause);
        }
        $body .= implode(' UNION ', $arr) . ' ';
    }
    return $body;
}
mrpatrickwest commented 9 years ago

Stephan won’t be back to work until next week. Just got back from the wedding reception.

So fork it, clone it, fix it, and when Stephan gets back we can push it back to the master.

Patrick

On Sep 22, 2014, at 9:11 PM, Han Wang notifications@github.com wrote:

In the getQueryConstraints() in config.php, the constraint clause for each $constraint_type shouldn't be in conjunction.

The code should be something like this:

public function getQueryConstraints(array $constraints) {

$body = "";     
foreach($constraints as $constraint_type => $constraint_values) {           
    $arr = array(); 
    foreach($constraint_values as $i => $constraint_value) {
        $constraint_clause = $this->getQueryConstraint($constraint_type, $constraint_value);
        array_push($arr, $constraint_clause);
    }
    $body .= implode(' UNION ', $arr) . ' ';
}
return $body;

} — Reply to this email directly or view it on GitHub.

zednis commented 9 years ago

This does not appear to be an issue in the current version.

This is the current version in github:

/**
* Return constraints component of SPARQL query
* @param array $constraints array of arrays with search constraints
* @return string constraints component of SPARQL query
*/
public function getQueryConstraints(array $constraints) {

    $arr = array(); 
    foreach($constraints as $constraint_type => $constraint_values) {           
        foreach($constraint_values as $i => $constraint_value) {
            $constraint_clause = $this->getQueryConstraint($constraint_type, $constraint_value);
            array_push($arr, $constraint_clause);
        }
    }
    return implode('UNION', $arr) . ' ';
}

@nahgnaw were you possibly referring to a previous version of the code?

edit: The reason I ask is because this file has not been changed from its original commit, so perhaps Han is referring to a version of the code from before it was pushed to github?

nahgnaw commented 9 years ago

With the current version of the getQueryConstraints() method, a query "find out dco:Project that with dco:Community1 and dco:Community2 and dco:Group1" would be something like this:

......
?s a dco:Project .
{?s dco:community dco:Community1} UNION
{?s dco:community dco:Community2} UNION
{?s dco:group dco:Group1}
......

But the correct query should be:

......
?s a dco:Project .
{?s dco:community dco:Community1} UNION
{?s dco:community dco:Community2}
{?s dco:group dco:Group1}
......

The "UNION" should be just between different values of the same constraint type, but not between different constraint types.