I have the following xml-schema for a movie database:
<movies>
<movie>
<title>A History of Violence</title>
<year>2005</year>
<country>USA</country>
<genre>Crime</genre>
<summary>Tom Stall, a humble family man and owner of a
popular neighborhood restaurant, lives a quiet but
fulfilling existence in the Midwest. One night Tom
foils a crime at his place of business and, to his
chagrin, is plastered all over the news for his
heroics. Following this, mysterious people follow
the Stalls' every move, concerning Tom more than
anyone else. As this situation is confronted, more
lurks out over where all these occurrences have
stemmed from compromising his marriage, family
relationship and the main characters' former
relations in the process.</summary>
<director>
<last_name>Cronenberg</last_name>
<first_name>David</first_name>
<birth_date>1943</birth_date>
</director>
<actor>
<first_name>Vigo</first_name>
<last_name>Mortensen</last_name>
<birth_date>1958</birth_date>
<role>Tom Stall</role>
</actor>
<actor>
<first_name>Maria</first_name>
<last_name>Bello</last_name>
<birth_date>1967</birth_date>
<role>Eddie Stall</role>
</actor>
<actor>
<first_name>Ed</first_name>
<last_name>Harris</last_name>
<birth_date>1950</birth_date>
<role>Carl Fogarty</role>
</actor>
<actor>
<first_name>William</first_name>
<last_name>Hurt</last_name>
<birth_date>1950</birth_date>
<role>Richie Cusack</role>
</actor>
</movie>
</movies>
I created now search fields for actors first/last_name; genre; country; year and role.
But the problem is, that it only works with the year and the genre.
If I use
genre or year: I get the right results
last_name;first_name; country; role: I get no result
I guess it has something todo with the multiple actors and multiple country elements but i couldn“t figure out how to solve it.
Here is my Xquery code:
xquery version "3.0";
(: :declare namespace util="http://exist-db.org/xquery/util";:)
declare option exist:serialize "method=xhtml media-type=text/html indent=yes";
let $year := lower-case(request:get-parameter('year', ''))
let $genre := request:get-parameter('genre', '')
let $first_name := request:get-parameter('first_name', '')
let $last_name := request:get-parameter('last_name', '')
let $country := request:get-parameter('country', '')
let $role := request:get-parameter('role', '')
let $movies := collection('/db/Movie/data')/movies/movie[if(not($genre)) then xs:boolean(1) else equals(genre, $genre)][if(not($year)) then xs:boolean(1) else equals(year, $year)][if(not($country)) then xs:boolean(1) else equals(//country, $country)][if(not($first_name)) then xs:boolean(1) else equals(//actor/first_name, $first_name)][if(not($last_name)) then xs:boolean(1) else equals(//actor/last_name, $last_name)][if(not($role)) then xs:boolean(1) else equals(//actor/role, $role)]
return
<html>
<head>
</head>
<body>
<h1>Search results:</h1>
<ol>{
for $movie in $movies
let $title := $movie/title/text()
let $year := $movie/year/text()
return
<li>{$title} ({$year})</li>
}</ol>
</body>
</html>
Thanks in advance! Greets