Skip to content

Commit

Permalink
Implement search by notation code. Fixes #456
Browse files Browse the repository at this point in the history
  • Loading branch information
osma committed May 12, 2016
1 parent 59a6d7b commit f3a962d
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
7 changes: 5 additions & 2 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -809,6 +809,7 @@ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $p
{
$valuesProp = $this->formatValues('?prop', $props);
$textcond = $this->generateConceptSearchQueryCondition($term, $searchLang);
$rawterm = str_replace('*', '', $term);

// extra conditions for label language, if specified
$labelcondLabel = ($lang) ? "LANGMATCHES(lang(?label), '$lang')" : "LANGMATCHES(lang(?label), lang(?match))";
Expand All @@ -835,8 +836,10 @@ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $p
WHERE {
$valuesProp
VALUES (?prop ?pri) { (skos:prefLabel 1) (skos:altLabel 3) (skos:hiddenLabel 5)}
$textcond
?s ?prop ?match
{ $textcond
?s ?prop ?match }
UNION
{ ?s skos:notation "$rawterm" }
OPTIONAL {
?s skos:prefLabel ?label .
FILTER ($labelcondLabel)
Expand Down
22 changes: 22 additions & 0 deletions tests/GenericSparqlTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -435,6 +435,28 @@ public function testQueryConceptsMatchHiddenLabel()
$this->assertEquals('Karppi', $actual[0]['prefLabel']);
}

/**
* @covers GenericSparql::queryConcepts
* @covers GenericSparql::generateConceptSearchQueryCondition
* @covers GenericSparql::generateConceptSearchQueryInner
* @covers GenericSparql::generateConceptSearchQuery
* @covers GenericSparql::formatFilterGraph
* @covers GenericSparql::transformConceptSearchResults
* @covers GenericSparql::transformConceptSearchResult
* @covers GenericSparql::shortenUri
*/
public function testQueryConceptsMatchNotation()
{
$voc = $this->model->getVocabulary('test');
$this->params->method('getRawSearchTerm')->will($this->returnValue('665'));
$this->params->method('getSearchTerm')->will($this->returnValue('665*'));
$this->params->method('getVocabIds')->will($this->returnValue(array('test')));
$actual = $this->sparql->queryConcepts(array($voc), null, null, $this->params);
$this->assertEquals(1, sizeof($actual));
var_dump($actual);
$this->assertEquals('http://www.skosmos.skos/test/ta112', $actual[0]['uri']);
}

/**
* @covers GenericSparql::queryConcepts
* @covers GenericSparql::generateConceptSearchQueryCondition
Expand Down

0 comments on commit f3a962d

Please sign in to comment.