Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Optimize alphabet letter query: use GRAPH instead of FROM #1098

Merged
merged 2 commits into from
Dec 7, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
52 changes: 28 additions & 24 deletions model/sparql/GenericSparql.php
Original file line number Diff line number Diff line change
Expand Up @@ -1227,7 +1227,7 @@ private function formatFilterConditions($letter, $lang) {
* @return string sparql query
*/
protected function generateAlphabeticalListQuery($letter, $lang, $limit, $offset, $classes, $showDeprecated = false, $qualifier = null) {
$fcl = $this->generateFromClause();
$gcl = $this->graphClause;
$classes = ($classes) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept');
$values = $this->formatValues('?type', $classes, 'uri');
$limitandoffset = $this->formatLimitAndOffset($limit, $offset);
Expand All @@ -1240,31 +1240,33 @@ protected function generateAlphabeticalListQuery($letter, $lang, $limit, $offset
$filterDeprecated="FILTER NOT EXISTS { ?s owl:deprecated true }";
}
$query = <<<EOQ
SELECT DISTINCT ?s ?label ?alabel ?qualifier $fcl
SELECT DISTINCT ?s ?label ?alabel ?qualifier
WHERE {
{
?s skos:prefLabel ?label .
FILTER (
$filtercondLabel
)
}
UNION
{
$gcl {
{
?s skos:altLabel ?alabel .
?s skos:prefLabel ?label .
FILTER (
$filtercondALabel
$filtercondLabel
)
}
UNION
{
?s skos:prefLabel ?label .
FILTER (langMatches(lang(?label), '$lang'))
{
?s skos:altLabel ?alabel .
FILTER (
$filtercondALabel
)
}
{
?s skos:prefLabel ?label .
FILTER (langMatches(lang(?label), '$lang'))
}
}
?s a ?type .
$qualifierClause
$filterDeprecated
$values
}
?s a ?type .
$qualifierClause
$filterDeprecated
$values
}
ORDER BY LCASE(STR(COALESCE(?alabel, ?label))) STR(?s) LCASE(STR(?qualifier)) $limitandoffset
EOQ;
Expand Down Expand Up @@ -1337,15 +1339,17 @@ public function queryConceptsAlphabetical($letter, $lang, $limit = null, $offset
* @return string sparql query
*/
private function generateFirstCharactersQuery($lang, $classes) {
$fcl = $this->generateFromClause();
$gcl = $this->graphClause;
$classes = (isset($classes) && sizeof($classes) > 0) ? $classes : array('http://www.w3.org/2004/02/skos/core#Concept');
$values = $this->formatValues('?type', $classes, 'uri');
$query = <<<EOQ
SELECT DISTINCT (ucase(str(substr(?label, 1, 1))) as ?l) $fcl WHERE {
?c skos:prefLabel ?label .
?c a ?type
FILTER(langMatches(lang(?label), '$lang'))
$values
SELECT DISTINCT (ucase(str(substr(?label, 1, 1))) as ?l) WHERE {
$gcl {
?c skos:prefLabel ?label .
?c a ?type
FILTER(langMatches(lang(?label), '$lang'))
$values
}
}
EOQ;
return $query;
Expand Down