{{!
@param str        language
@param str        search-term (optional)
@param Array<IRI> search-constructs (optional)
}}

{{> sparql/prefixes.mustache }}

SELECT DISTINCT (REPLACE(STR(?exercise), "^.*\\/([^/]+)$", "$1") AS ?id)
                ?name
                ?difficultyLabel
                ?difficultyLevel
WHERE {
  ?exercise a sp:Query ;
    rdfs:label ?name ;
    sparqlab:hasDifficulty [
      skos:notation ?difficultyLevel ;
      skos:prefLabel ?difficultyLabel
    ] .
  FILTER langMatches(lang(?difficultyLabel), "{{language}}")

  {{#search-term}}
  ?exercise rdfs:comment ?description .
  BIND (LCASE("{{search-term}}") AS ?searchTerm)
  FILTER (CONTAINS(LCASE(?name), ?searchTerm)
          ||
          CONTAINS(LCASE(?description), ?searchTerm)) 
  {{/search-term}}

  {{#search-constructs}}
  ?exercise dcterms:subject <{{.}}> .
  {{/search-constructs}}
}

{{!
@param str        language
@param str        search-term (optional)
@param Array<IRI> search-constructs (optional)
}}

{{> sparql/prefixes.mustache }}

SELECT DISTINCT (REPLACE(STR(?exercise), "^.*\\/([^/]+)$", "$1") AS ?id)
                ?name
                ?difficultyLabel
                ?difficultyLevel
WHERE {
  ?exercise a sp:Query ;
    rdfs:label ?name ;
    sparqlab:hasDifficulty [
      skos:notation ?difficultyLevel ;
      skos:prefLabel ?difficultyLabel
    ] .
  FILTER langMatches(lang(?difficultyLabel), "{{language}}")

  {{#search-term}}
  ?exercise rdfs:comment ?description .
  BIND (LCASE("{{search-term}}") AS ?searchTerm)
  FILTER (CONTAINS(LCASE(?name), ?searchTerm)
          ||
          CONTAINS(LCASE(?description), ?searchTerm)) 
  {{/search-term}}

  {{#search-constructs}}
  ?exercise dcterms:subject <{{.}}> .
  {{/search-constructs}}
}
ORDER BY ?difficultyLevel

Order exercises found by difficulty
Order exercises found by difficulty
