1
votes

I want to search "Star Wars" across both TV series (http://www.wikidata.org/entity/Q5398426) and films (http://www.wikidata.org/entity/Q11424). The following SPARQL is for searching movies:

# search movies by name
SELECT DISTINCT ?item ?name WHERE {
  ?item wdt:P31 wd:Q11424.
  ?item rdfs:label ?queryByTitle.
  OPTIONAL { ?item wdt:P1476 ?name. }
  #FILTER(REGEX(?queryByTitle, "star wars", "i"))
  FILTER(contains(lcase(?queryByTitle), "star wars"))
}
LIMIT 100

Any idea how I can search by TV Series as well?

1
Replace ?item wdt:P31 wd:Q11424. with VALUES ?type {wd:Q5398426 wd:Q11424} ?item wdt:P31 ?type . - UninformedUser

1 Answers

1
votes

@AKSW answered the question. Here's the full gist for anyone searching in the future.

SELECT DISTINCT ?item ?name WHERE {
  VALUES ?type {wd:Q5398426 wd:Q11424} ?item wdt:P31 ?type .
  ?item rdfs:label ?queryByTitle.
  OPTIONAL { ?item wdt:P1476 ?name. }
  FILTER(REGEX(?queryByTitle, "star wars", "i"))
}
LIMIT 100