0
我有以下XML的架構一個電影數據庫:的Xquery使用多個搜索領域
<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>
我現在創建的搜索字段演員第一/姓氏;類型;國家;年和角色。
但問題是,它只與去年和體裁的作品。
如果我使用
流派或年:我得到正確的結果
姓氏; FIRST_NAME;國家;作用:我得不到結果
我想它與多個演員和多個國家的元素有些待辦事項,但我無法弄清楚如何解決它。
這裏是我的XQuery代碼:
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>
提前感謝! 電賀
謝謝,我糾正了錯字,但它沒有工作:(現在我也得到了last_name沒有結果了 – user3181473
@ user3181473:試圖刪除//國家/地區等//呢?他們是不必要的。他們不應該傷害,我想,但不使用//(幾乎)總是更好.. – grtjn