Created
March 25, 2010 13:06
-
-
Save dscape/343528 to your computer and use it in GitHub Desktop.
Search, Updates and Range Indexes
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
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
declare function local:build-query($text as xs:string) { | |
cts:or-query(( | |
cts:word-query($text, (), 1), | |
cts:element-word-query( | |
xs:QName("ts:title"), $text, (), 2 ))) } ; | |
declare function local:search-rating($song) { | |
cts:score($song) | |
} ; | |
for $song in cts:search(fn:doc(), local:build-query("night")) [1 to 10] | |
return <div> | |
{ xs:string($song//ts:title) } | |
[ { local:search-rating($song) } ] | |
</div> |
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
import module namespace s="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; | |
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
let $options := | |
<s:options> | |
<s:transform-results apply="raw"/> | |
</s:options> | |
return | |
for $song in s:search("night", $options)/s:result | |
return | |
<div class="songname"> | |
{ fn:string($song//ts:title) } | |
</div> |
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
(: Showing the difference between contains and search - relevance vs doc order :) | |
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
for $song in /ts:top-song | |
[ fn:contains(., "night") ] [1 to 10] | |
return <div> | |
{ xs:string($song/ts:title) } | |
</div> | |
(: Using URI to get the title from a document :) | |
import module namespace s="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; | |
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
for $result in s:search("night")/s:result | |
let $title := fn:string( fn:doc($result/@uri)//ts:title ) | |
return | |
<div class="songname"> | |
{ $title } | |
</div> |
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
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
(:::::::::::::::::: update ::::::::::::::) | |
(: xdmp:node-insert-child( | |
: (//ts:p[cts:contains(., "yeah")])[6], | |
: element stars { "3" } ) :) | |
(::::::::::: selection ::::::::::::::::::) | |
(//ts:p[cts:contains(., "yeah")])[6] |
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
xdmp:document-properties("/images/Michael-Jackson+The-Way-You-Make-Me-Feel.jpg") |
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
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
for $weeks in //ts:weeks | |
let $week := $weeks/ts:week | |
let $count := fn:count ( $week ) | |
let $last := fn:max( xs:date( $week ) ) | |
return ( | |
xdmp:node-insert-child($weeks, attribute count { $count } ), | |
xdmp:node-insert-child($weeks, attribute last { $last } ) ) |
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
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
for $week in //ts:weeks/ts:week | |
return if ($week castable as xs:date) | |
then () | |
else ( xdmp:node-delete($week), "Deleted one node" ) |
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
(: set up range indexes first :) | |
declare namespace ts="http://marklogic.com/MLU/top-songs"; | |
for $i in cts:element-attribute-values( | |
xs:QName("ts:weeks"), xs:QName("count"), (), "frequency-order" ) | |
return | |
<count i="{$i}"> | |
{ cts:frequency($i) } | |
</count> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment