views:

38

answers:

1

I'm using this line in a SPARQL query in my python program:

FILTER regex(?name, "%s", "i" )

(where %s is the search text entered by the user)

I want this to match if either ?name or ?featurename contains %s, but I can't seem to find any documentation or tutorial for using regex(). I tried a couple things that seemed reasonable:

FILTER regex((?name | ?featurename), "%s", "i" )
FILTER regex((?name || ?featurename), "%s", "i" )
FILTER regex((?name OR ?featurename), "%s", "i" )
FILTER regex((?name, ?featurename), "%s", "i" )

and each of those without the ()

FILTER regex(?name, "%s", "i" ) || regex(?featurename, "%s", "i" )

What's the right way to do this? Thanks

UPDATE: Using UNION works. But I figured out that it also works if you just repeat the regex() part like so:

FILTER (regex(?name, "%s", "i") || regex(?featurename, "%s", "i" ))

Both solutions seem a little messy in that you have to use a 2-element tuple with copies of the same string to fill in both %ss.

+1  A: 

What about this?

SELECT ?thing
WHERE {
  { 
    ?thing x:name ?name .
    FILTER regex(?name, "%s", "i" )
  } UNION {
    ?thing x:featurename ?name .
    FILTER regex(?featurename, "%s", "i" )
  }
}
glenn mcdonald