From 6555f84784c64decb8a199714f8a5b49107af025 Mon Sep 17 00:00:00 2001 From: Mika Vaara Date: Wed, 26 Jan 2022 18:14:33 +0200 Subject: [PATCH 1/5] Generates a search result containing zeros in the beginning of the notation code but not in the middle of it (YKL). At the moment it causes problems in searches related to the vocabularies not using notation code - prefLaber combination (such as Juho). --- model/ConceptSearchParameters.php | 1 + model/sparql/GenericSparql.php | 4 +++- 2 files changed, 4 insertions(+), 1 deletion(-) diff --git a/model/ConceptSearchParameters.php b/model/ConceptSearchParameters.php index 6975f39ad..d8eb20e11 100644 --- a/model/ConceptSearchParameters.php +++ b/model/ConceptSearchParameters.php @@ -68,6 +68,7 @@ public function getArrayClass() public function getSearchTerm() { $term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query'); + $term = ($term == 0) ? '0' : $term; if (!$term && $this->rest) $term = $this->request->getQueryParamRaw('label'); $term = trim($term); // surrounding whitespace is not considered significant diff --git a/model/sparql/GenericSparql.php b/model/sparql/GenericSparql.php index 6605102aa..ef07f9a17 100644 --- a/model/sparql/GenericSparql.php +++ b/model/sparql/GenericSparql.php @@ -922,6 +922,7 @@ protected function generateConceptSearchQueryCondition($term, $searchLang) */ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph) { + error_log('term >>> ' . $term . '<<<<'); $valuesProp = $this->formatValues('?prop', $props); $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); @@ -979,7 +980,8 @@ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $p } $hitgroup EOQ; - + error_log('>>>>>' . $textcond . '<<<<<'); + error_log('>>>>>' . $query . '<<<<<'); return $query; } /** From 3fe58fab7939398651cc557ac28c35c569877db4 Mon Sep 17 00:00:00 2001 From: Mika Vaara Date: Tue, 15 Feb 2022 17:45:01 +0200 Subject: [PATCH 2/5] Using '0' as a search term returns a correct list of the concepts --- model/ConceptSearchParameters.php | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/model/ConceptSearchParameters.php b/model/ConceptSearchParameters.php index d8eb20e11..bf03e6c21 100644 --- a/model/ConceptSearchParameters.php +++ b/model/ConceptSearchParameters.php @@ -67,9 +67,8 @@ public function getArrayClass() public function getSearchTerm() { - $term = $this->request->getQueryParamRaw('q') ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query'); - $term = ($term == 0) ? '0' : $term; - if (!$term && $this->rest) + $term = $this->request->getQueryParamRaw('q') !== null ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query'); + if (($term !== null || strlen(trim($term)) === 0) && $this->rest) $term = $this->request->getQueryParamRaw('label'); $term = trim($term); // surrounding whitespace is not considered significant $term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184 From 638849f5c233293f90fe69daf869659a2d07b4c4 Mon Sep 17 00:00:00 2001 From: Mika Vaara Date: Wed, 16 Feb 2022 15:53:00 +0200 Subject: [PATCH 3/5] A null check for the search term fixed. In addition, a naming problem related to the dataProvider for searching with zero (API) fixed. --- model/ConceptSearchParameters.php | 2 +- model/sparql/GenericSparql.php | 3 --- tests/RestControllerTest.php | 4 ++-- 3 files changed, 3 insertions(+), 6 deletions(-) diff --git a/model/ConceptSearchParameters.php b/model/ConceptSearchParameters.php index bf03e6c21..7cf84c175 100644 --- a/model/ConceptSearchParameters.php +++ b/model/ConceptSearchParameters.php @@ -68,7 +68,7 @@ public function getArrayClass() public function getSearchTerm() { $term = $this->request->getQueryParamRaw('q') !== null ? $this->request->getQueryParamRaw('q') : $this->request->getQueryParamRaw('query'); - if (($term !== null || strlen(trim($term)) === 0) && $this->rest) + if (($term === null || strlen(trim($term)) === 0) && $this->rest) $term = $this->request->getQueryParamRaw('label'); $term = trim($term); // surrounding whitespace is not considered significant $term = Normalizer::normalize( $term, Normalizer::FORM_C ); //Normalize decomposed unicode characters #1184 diff --git a/model/sparql/GenericSparql.php b/model/sparql/GenericSparql.php index ef07f9a17..c56d8a411 100644 --- a/model/sparql/GenericSparql.php +++ b/model/sparql/GenericSparql.php @@ -922,7 +922,6 @@ protected function generateConceptSearchQueryCondition($term, $searchLang) */ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $props, $unique, $filterGraph) { - error_log('term >>> ' . $term . '<<<<'); $valuesProp = $this->formatValues('?prop', $props); $textcond = $this->generateConceptSearchQueryCondition($term, $searchLang); @@ -980,8 +979,6 @@ protected function generateConceptSearchQueryInner($term, $lang, $searchLang, $p } $hitgroup EOQ; - error_log('>>>>>' . $textcond . '<<<<<'); - error_log('>>>>>' . $query . '<<<<<'); return $query; } /** diff --git a/tests/RestControllerTest.php b/tests/RestControllerTest.php index 2bc12d4d8..a63f42fd4 100644 --- a/tests/RestControllerTest.php +++ b/tests/RestControllerTest.php @@ -81,7 +81,7 @@ public function testSearchJsonLdWithAdditionalFields() { /** * Data provider for testSearchWithZero test. */ - public function testSearchWithZeroData(): array { + public function provideSearchWithZeroData(): array { return [ ['0', true], ['1', true], @@ -94,7 +94,7 @@ public function testSearchWithZeroData(): array { /** * @covers RestController::search - * @dataProvider testSearchWithZeroData + * @dataProvider provideSearchWithZeroData * @param $query string the search query * @param $isSuccess bool whether the request must succeed or fail */ From 8dcc4a2c952e23788af52003115e7062c6ecacb2 Mon Sep 17 00:00:00 2001 From: Mika Vaara Date: Wed, 16 Feb 2022 18:25:56 +0200 Subject: [PATCH 4/5] Added tests for the searches with zero ('0') --- tests/ConceptSearchParametersTest.php | 11 +++++++ .../test-vocab-data/test-notation-search.ttl | 33 +++++++++++++++++++ tests/testconfig.ttl | 15 +++++++++ 3 files changed, 59 insertions(+) create mode 100644 tests/test-vocab-data/test-notation-search.ttl diff --git a/tests/ConceptSearchParametersTest.php b/tests/ConceptSearchParametersTest.php index dab94397c..9bd3d8c0f 100644 --- a/tests/ConceptSearchParametersTest.php +++ b/tests/ConceptSearchParametersTest.php @@ -86,6 +86,16 @@ public function testGetSearchTerm() { $this->assertEquals('test', $params->getSearchTerm()); } + /** + * @covers ConceptSearchParameters::getSearchTerm + * Is created particularly for searches not using REST + */ + public function testSearchTermWithoutRest() { + $params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl'), false); + $this->request->method('getQueryParamRaw')->will($this->returnValue('0')); + $this->assertEquals('0*', $params->getSearchTerm()); + } + /** * @covers ConceptSearchParameters::getTypeLimit * @covers ConceptSearchParameters::getDefaultTypeLimit @@ -230,4 +240,5 @@ public function testGetAdditionalFields() { $params = new ConceptSearchParameters($this->request, new GlobalConfig('/../tests/testconfig.ttl')); $this->assertEquals(array('broader', 'prefLabel'), $params->getAdditionalFields()); } + } diff --git a/tests/test-vocab-data/test-notation-search.ttl b/tests/test-vocab-data/test-notation-search.ttl new file mode 100644 index 000000000..8cf3c8691 --- /dev/null +++ b/tests/test-vocab-data/test-notation-search.ttl @@ -0,0 +1,33 @@ +@prefix dc: . +@prefix dc11: . +@prefix dct: . +@prefix test: . +@prefix meta: . +@prefix owl: . +@prefix rdf: . +@prefix rdfs: . +@prefix skos: . +@prefix skosmos: . +@prefix xml: . +@prefix xsd: . +@prefix mads: . + +meta:TestClass a owl:Class ; + rdfs:subClassOf skos:Concept ; + rdfs:label "Test class"@en . + +skosmos:testprop a rdf:Property ; + rdfs:label "Skosmos test property"@en . + +test:ta02 a skos:Concept, meta:TestClass ; + skos:inScheme test:conceptscheme ; + skos:prefLabel "007 - My name is Bond, James Bond"@en ; + skos:notation "0" ; + skos:topConceptOf test:conceptscheme . + +test:ta03 a skos:Concept, meta:TestClass ; + skos:inScheme test:conceptscheme ; + skos:prefLabel "008 - For England James!"@en ; + skos:notation "0.01" ; + skos:topConceptOf test:conceptscheme . + diff --git a/tests/testconfig.ttl b/tests/testconfig.ttl index 923f404ec..42145523c 100644 --- a/tests/testconfig.ttl +++ b/tests/testconfig.ttl @@ -99,6 +99,21 @@ skosmos:language "en"; skosmos:sparqlGraph . +:test-notation-search a skosmos:Vocabulary, void:Dataset ; + dc:title "Test searches with a notation"@en ; + dc:subject :cat_science ; + dc:type mdrtype:ONTOLOGY ; + void:uriSpace "http://www.skosmos.skos/test-notation-search/"; + skos:prefLabel "Test searches with a notation"@en ; + skosmos:defaultLanguage "en"; + skosmos:feedbackRecipient "developer@vocabulary.org"; + skosmos:sortByNotation "true"; + skosmos:showNotation "true"; + skosmos:showNotationAsProperty "true"; + skosmos:searchByNotation "true" ; + skosmos:language "en"; + skosmos:sparqlGraph . + :test-qualified-broader a skosmos:Vocabulary, void:Dataset ; dc:title "Test qualified alphabetical listing queries (skos:broader)"@en ; dc:subject :cat_science ; From e5b066d47340324ecc7b3683a65741479ca6f4bc Mon Sep 17 00:00:00 2001 From: Osma Suominen Date: Thu, 3 Mar 2022 15:38:42 +0200 Subject: [PATCH 5/5] Remove test data that wasn't actually used --- .../test-vocab-data/test-notation-search.ttl | 33 ------------------- tests/testconfig.ttl | 15 --------- 2 files changed, 48 deletions(-) delete mode 100644 tests/test-vocab-data/test-notation-search.ttl diff --git a/tests/test-vocab-data/test-notation-search.ttl b/tests/test-vocab-data/test-notation-search.ttl deleted file mode 100644 index 8cf3c8691..000000000 --- a/tests/test-vocab-data/test-notation-search.ttl +++ /dev/null @@ -1,33 +0,0 @@ -@prefix dc: . -@prefix dc11: . -@prefix dct: . -@prefix test: . -@prefix meta: . -@prefix owl: . -@prefix rdf: . -@prefix rdfs: . -@prefix skos: . -@prefix skosmos: . -@prefix xml: . -@prefix xsd: . -@prefix mads: . - -meta:TestClass a owl:Class ; - rdfs:subClassOf skos:Concept ; - rdfs:label "Test class"@en . - -skosmos:testprop a rdf:Property ; - rdfs:label "Skosmos test property"@en . - -test:ta02 a skos:Concept, meta:TestClass ; - skos:inScheme test:conceptscheme ; - skos:prefLabel "007 - My name is Bond, James Bond"@en ; - skos:notation "0" ; - skos:topConceptOf test:conceptscheme . - -test:ta03 a skos:Concept, meta:TestClass ; - skos:inScheme test:conceptscheme ; - skos:prefLabel "008 - For England James!"@en ; - skos:notation "0.01" ; - skos:topConceptOf test:conceptscheme . - diff --git a/tests/testconfig.ttl b/tests/testconfig.ttl index 42145523c..923f404ec 100644 --- a/tests/testconfig.ttl +++ b/tests/testconfig.ttl @@ -99,21 +99,6 @@ skosmos:language "en"; skosmos:sparqlGraph . -:test-notation-search a skosmos:Vocabulary, void:Dataset ; - dc:title "Test searches with a notation"@en ; - dc:subject :cat_science ; - dc:type mdrtype:ONTOLOGY ; - void:uriSpace "http://www.skosmos.skos/test-notation-search/"; - skos:prefLabel "Test searches with a notation"@en ; - skosmos:defaultLanguage "en"; - skosmos:feedbackRecipient "developer@vocabulary.org"; - skosmos:sortByNotation "true"; - skosmos:showNotation "true"; - skosmos:showNotationAsProperty "true"; - skosmos:searchByNotation "true" ; - skosmos:language "en"; - skosmos:sparqlGraph . - :test-qualified-broader a skosmos:Vocabulary, void:Dataset ; dc:title "Test qualified alphabetical listing queries (skos:broader)"@en ; dc:subject :cat_science ;