Created
July 23, 2012 20:03
-
-
Save anonymous/3165889 to your computer and use it in GitHub Desktop.
Search Constraints in XQuery MarkLogic
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
xquery version "1.0-ml"; | |
module namespace so="http://try.marklogic.com/search-options"; | |
declare default function namespace "http://www.w3.org/2005/xpath-functions"; | |
import module namespace searchdev = | |
"http://marklogic.com/appservices/search/searchdev" | |
at "/MarkLogic/appservices/search/custom-parse.xqy"; | |
declare namespace opt = "http://marklogic.com/appservices/search"; | |
declare namespace appl="http://ap.org/schemas/03/2005/appl"; | |
declare function so:term-option-to-search-option($opts as element()?) | |
as element()* | |
{ | |
for $opt in $opts/opt:term-option | |
where not(starts-with($opt, "lang=")) | |
return <cts:option>{$opt/string()}</cts:option> | |
}; | |
declare function so:myterm($ps as map:map, $term-elem as element()?) | |
as schema-element(cts:query) | |
{ | |
( | |
let $token := searchdev:current($ps) | |
let $options := so:term-option-to-search-option($term-elem) | |
return | |
<cts:or-query qtextconst="{ $token }"> | |
{ cts:element-attribute-word-query(xs:QName("appl:Occurrence"), | |
xs:QName("Id"), string($token), $options, 300) } | |
{ cts:element-attribute-word-query(xs:QName("appl:Occurrence"), | |
xs:QName("Value"), string($token), $options, 300) } | |
{ cts:element-word-query(xs:QName("appl:FilingSubject"), string($token), | |
$options, 300) } | |
{ cts:element-word-query(xs:QName("appl:FilingSubSubject"), string($token), | |
$options, 300) } | |
{ cts:element-word-query(xs:QName("appl:FilingTopic"), string($token), | |
$options, 300) } | |
{ cts:element-word-query(xs:QName("appl:Scene"), string($token), | |
$options, 300) } | |
{ cts:element-word-query(xs:QName("appl:HeadLine"), string($token), | |
$options, 200) } | |
{ cts:element-word-query(xs:QName("appl:ExtendedHeadLine"), string($token), | |
$options, 100) } | |
{ cts:element-word-query(xs:QName("appl:Title"), string($token), | |
$options, 100) } | |
{ cts:element-attribute-word-query(xs:QName("appl:Property"), | |
xs:QName("Value"), string($token), $options, 10) } | |
{ cts:element-word-query(xs:QName("appl:City"), string($token), | |
$options, 10) } | |
{ cts:element-word-query(xs:QName("appl:CountryName"), string($token), | |
$options, 10) } | |
{ cts:element-word-query(xs:QName("appl:CountryAreaName"), string($token), | |
$options, 10) } | |
{ cts:element-word-query(xs:QName("appl:block"), string($token), | |
$options, 1) } | |
{ cts:element-word-query(xs:QName("appl:DateLine"), string($token), | |
$options, 1) } | |
{ cts:element-word-query(xs:QName("appl:KeywordLine"), string($token), | |
$options, 0.75) } | |
{ cts:element-word-query(xs:QName("appl:LocationLine"), string($token), | |
$options, 0.75) } | |
{ cts:element-word-query(xs:QName("appl:OverLine"), string($token), | |
$options, 0.75) } | |
{ cts:element-word-query(xs:QName("appl:SlugLine"), string($token), | |
$options, 0.75) } | |
{ cts:element-attribute-word-query(xs:QName("appl:FirstCreated"), | |
xs:QName("Year"), string($token), $options, 0.25) } | |
{ cts:element-word-query(xs:QName("appl:Fixture"), string($token), | |
$options, 0.25) } | |
{ cts:element-word-query(xs:QName("appl:ItemContentType"), string($token), | |
$options, 0.25) } | |
{ cts:word-query(string($token), | |
$options, 0.01) } | |
</cts:or-query> | |
, | |
searchdev:advance($ps) | |
) | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment