Hi, I'm new to xquery and MarkLogic, and am stuck. I'm working
on an advanced search form that takes user input. I must have
missed something because the codes I wrote (that work) are so
verbose. There must be better ways. Hope you could help.
Thanks. -Jane
-----------------------------------------------------------
let $subj := "administrative"
let $title :="AC"
let $op :="AND"
(:
The above 3 represent some of the variables inputted by a user
with actually unknown values beforehand. $q1, $q2 and $3 below
are simplified processing. But records/record[$q3] gets me
wrong results. The commented out block at the end for $q_ok
actually is what I want to do but in a dynamic way and is what
/records/record[$q3] should have got me.
Simplified data structure looks something like:
<records>
- <record>
<title>The A-Core: Metadata about Content Metadata</title>
<date>1999-06-30</date>
<subject>administrative metadata</subject>
</record>
-<record>
<title>AC - Administrative Components</title>
<subject>administrative metadata</subject>
</record>
</records>
:)
let
$q1 :=
if (string-length($subj) and $op ='AND' )
then concat ("cts:contains(subject,
cts:and-query(cts:word-query('",
$subj, "', 'case-insensitive'))) and ")
else (),
$q2 :=
if (string-length($subj) and $op ='AND' )
then concat ("cts:contains(title,
cts:and-query(cts:word-query('",
$title, "', 'case-insensitive'))) and ")
else (),
$q3 :=fn:replace(concat ($q1, $q2), "and $", "")
return (<P>{:=/records/record[$q3]}</P>)
(:
let $q_ok :=/records/record[cts:contains(subject,
cts:and-query(cts:word-query(
$subj, 'case-insensitive'))) and
cts:contains(title, cts:and-query(cts:word-query($title,
'case-insensitive'))) ]
return (<P>{$q_ok}</P>)
:)
_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general