VOS.VirtTipsAndTricksGuideInsensSearch

How Can I Perform Case Insensitive Search across multiple Literal values with Virtuoso?

If you use contains, it will make an approximate filtering of results, its is therefore best to use FILTER with bif:lower.

For example with the following RDF triples loaded in Virtuoso:


<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"An?lisis" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Aut?nomas" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Autonom?a de gobierno" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Autonom?a" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Auton?mica" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Com?n" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Comunidades" .
<http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D><http://rdfs.org/sioc/types#Tag>"Cr?tico" .

The following query is case sensitive, thus no data is returned as is expected:


SQL> SPARQL
PREFIX sioc_t:<http://rdfs.org/sioc/types#>
SELECT DISTINCT ?s
FROM <http://j.com>
WHERE 
  { 
    ?s sioc_t:Tag ?Tag.  FILTER ( ?Tag in ('analisi', 'autonomas', 
                                           'autonomia de gobierno', 
                                           'autonomia', 'autonomica', 
                                           'comun', 'comunidades', 'critico' ) )
  }

-- Query result:
s
ANY
No. of rows in result: 0 

Changing the query to use the Virtuoso bif:lower function a case insensitive filter is performed returning one distinct row:


SQL>SPARQL 
PREFIX sioc_t:<http://rdfs.org/sioc/types#>
SELECT DISTINCT ?s
FROM <http://j.com>
WHERE 
  { 
    ?s sioc_t:Tag ?Tag.  FILTER ( bif:lower(str(?Tag)) in ('analisi', 'autonomas', 
                                                           'autonomia de gobierno', 
                                                           'autonomia', 'autonomica', 
                                                           'comun', 'comunidades', 'critico' ) )
  }

-- Query result:
s
ANY
 http://gnoss/000066A5-E5C4-4317-AC9F-4A226E65AE4D
No. of rows in result: 1 

Related