@@ -1302,6 +1302,7 @@ WHERE
13021302 <!-- trigger typeahead in the search bar -->
13031303
13041304 <xsl : template match =" input[@id = 'uri']" mode =" ixsl:onkeyup" priority =" 1" >
1305+ <xsl : param name =" var-name" select =" 'label'" as =" xs:string" />
13051306 <xsl : param name =" text" select =" ixsl:get(., 'value')" as =" xs:string?" />
13061307 <xsl : param name =" menu" select =" following-sibling::ul" as =" element()" />
13071308 <xsl : param name =" delay" select =" 400" as =" xs:integer" />
@@ -1353,14 +1354,40 @@ WHERE
13531354 <xsl : with-param name =" menu" select =" $menu" />
13541355 </xsl : call-template >
13551356 </xsl : when >
1356- <!-- if the input is not a URI, execute a keyword search with SPARQL regex() -->
1357+ <!-- if the input is not a URI, execute a keyword search with SPARQL regex() -->
13571358 <xsl : when test =" not(starts-with(ixsl:get(., 'value'), 'http://')) and not(starts-with(ixsl:get(., 'value'), 'https://'))" >
1358- <!-- TO-DO: refactor query building using XSLT -->
13591359 <xsl : variable name =" select-builder" select =" ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'SelectBuilder'), 'fromString', [ $select-string ])" />
1360- <!-- pseudo JS code: SPARQLBuilder.SelectBuilder.fromString(select-builder).wherePattern(SPARQLBuilder.QueryBuilder.filter(SPARQLBuilder.QueryBuilder.regex(QueryBuilder.var("label"), QueryBuilder.term(QueryBuilder.str($text))))) -->
1360+ <xsl : variable name =" select-json-string" select =" ixsl:call(ixsl:get(ixsl:window(), 'JSON'), 'stringify', [ ixsl:call($select-builder, 'build', []) ])" as =" xs:string" />
1361+ <xsl : variable name =" select-xml" select =" json-to-xml($select-json-string)" as =" document-node()" />
1362+ <!-- append FILTER(regex()) -->
1363+ <xsl : variable name =" select-xml" as =" document-node()" >
1364+ <xsl : document >
1365+ <xsl : apply-templates select =" $select-xml" mode =" ldh:add-regex-filter" >
1366+ <xsl : with-param name =" var-name" select =" $var-name" tunnel =" yes" />
1367+ <xsl : with-param name =" pattern" select =" $text" tunnel =" yes" />
1368+ <xsl : with-param name =" flags" select =" 'iq'" tunnel =" yes" /> <!-- case insensitive, ignore meta-characters: https://www.w3.org/TR/xpath-functions-31/#flags -->
1369+ </xsl : apply-templates >
1370+ </xsl : document >
1371+ </xsl : variable >
1372+ <!-- set LIMIT -->
1373+ <xsl : variable name =" select-xml" as =" document-node()" >
1374+ <xsl : document >
1375+ <xsl : apply-templates select =" $select-xml" mode =" ldh:replace-limit" />
1376+ </xsl : document >
1377+ </xsl : variable >
1378+ <!-- wrap SELECT into a DESCRIBE -->
1379+ <xsl : variable name =" query-xml" as =" element()" >
1380+ <xsl : apply-templates select =" $select-xml" mode =" ldh:wrap-describe" />
1381+ </xsl : variable >
1382+ <xsl : variable name =" query-json-string" select =" xml-to-json($query-xml)" as =" xs:string" />
1383+ <xsl : variable name =" query-json" select =" ixsl:call(ixsl:get(ixsl:window(), 'JSON'), 'parse', [ $query-json-string ])" />
1384+ <xsl : variable name =" query-string" select =" ixsl:call(ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'SelectBuilder'), 'fromQuery', [ $query-json ]), 'toString', [])" as =" xs:string" />
1385+ <!--
1386+ <xsl:variable name="select-builder" select="ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'SelectBuilder'), 'fromString', [ $select-string ])"/>
13611387 <xsl:variable name="select-builder" select="ixsl:call($select-builder, 'wherePattern', [ ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'QueryBuilder'), 'filter', [ ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'QueryBuilder'), 'regex', [ ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'QueryBuilder'), 'str', [ ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'QueryBuilder'), 'var', [ 'label' ]) ]), ixsl:call(ixsl:get(ixsl:get(ixsl:window(), 'SPARQLBuilder'), 'QueryBuilder'), 'term', [ ac:escape-regex($text) ]), true() ] ) ] ) ])"/>
13621388 <xsl:variable name="select-string" select="ixsl:call($select-builder, 'toString', [])" as="xs:string"/>
13631389 <xsl:variable name="query-string" select="ac:build-describe($select-string, $limit, (), (), true())" as="xs:string"/>
1390+ -->
13641391 <xsl : variable name =" service-uri" select =" xs:anyURI(ixsl:get(id('search-service'), 'value'))" as =" xs:anyURI?" />
13651392 <xsl : variable name =" service" select =" key('resources', $service-uri, ixsl:get(ixsl:window(), 'LinkedDataHub.apps'))" as =" element()?" />
13661393 <xsl : variable name =" endpoint" select =" ($service/sd:endpoint/@rdf:resource/xs:anyURI(.), resolve-uri('sparql', $ldt:base))[1]" as =" xs:anyURI" />
0 commit comments