The following example describes how to optimize query performance using bif functions.
SELECT DISTINCT ?r (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as ?_n_f_t_m_ex_ WHERE { { ?r ?v1 ?v2 . ?v2 bif:contains 'lego' . } UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 . ?v4 rdfs:subPropertyOf rdfs:label . ?v2 bif:contains 'lego' . } . } LIMIT 10
SELECT DISTINCT ?r (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as ?_n_f_t_m_ex_ WHERE { { ?r ?v1 ?v2 . ?v2 bif:contains 'lego' . } UNION { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 . ?v4 rdfs:subPropertyOf rdfs:label . ?v2 bif:contains 'lego' . } . ?r nao:userVisible "1"^^xsd:int . } LIMIT 10
?r ?v1 ?v2 . ?v2 bif:contains 'lego' . -- can be replaced with: graph ?g { ?r ?v1 ?v2 . ?r nao:userVisible "1"^^xsd:int . ?v2 bif:contains 'lego' . }
PREFIX nao: <http://www.semanticdesktop.org/ontologies/2007/08/15/nao#> SELECT DISTINCT ?r (bif:concat(bif:search_excerpt(bif:vector('lego'), ?v2))) as ?_n_f_t_m_ex_ WHERE { { { SELECT DISTINCT ?r ?v2 WHERE { ?r ?v1 ?v2 . ?v2 bif:contains 'lego' . ?r nao:userVisible "1"^^xsd:int . } LIMIT 10 } } UNION { { SELECT DISTINCT ?r ?v2 WHERE { ?r ?v1 ?v3 . ?v3 ?v4 ?v2 . ?v4 rdfs:subPropertyOf rdfs:label . ?v2 bif:contains 'lego' . ?r nao:userVisible "1"^^xsd:int . } LIMIT 10 } } } LIMIT 10