Skip to content
This repository has been archived by the owner on Nov 9, 2022. It is now read-only.

Commit

Permalink
Outputting the snippet in JSON the same as in XML.
Browse files Browse the repository at this point in the history
  • Loading branch information
ryangrimm committed Jan 4, 2012
1 parent 629e535 commit 93b66bd
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 25 deletions.
35 changes: 11 additions & 24 deletions corona/lib/common.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -267,33 +267,20 @@ declare function common:humanOperatorToMathmatical(
};

declare function common:translateSnippet(
$snippet as element(search:snippet),
$outputType as xs:string
$snippet as element(search:snippet)
) as item()*
{
if($outputType = "json")
then json:array(
for $match in $snippet/search:match
return
string-join(
for $node in $match/node()
return
if($node instance of element(search:highlight))
then concat("<span class='hit'>", string($node), "</span>")
else string($node)
, "")
for $match in $snippet/search:match
let $path := replace($match/@path, '^fn:doc\("[^"]*"\)', "")
return concat("<span class='match' path='", $path, "'>",
string-join(
for $node in $match/node()
return
if($node instance of element(search:highlight))
then concat("<span class='hit'>", string($node), "</span>")
else string($node)
, ""), "</span>"
)
else
for $match in $snippet/search:match
let $path := replace($match/@path, '^fn:doc\("[^"]*"\)', "")
return concat("<span class='match' path='", $path, "'>",
string-join(
for $node in $match/node()
return
if($node instance of element(search:highlight))
then concat("<span class='hit'>", string($node), "</span>")
else string($node)
, ""), "</span>")
};

declare function common:dualStrftime(
Expand Down
2 changes: 1 addition & 1 deletion corona/lib/store.xqy
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ declare function store:outputDocument(

let $snippet :=
if($include = ("snippet", "all") and exists($highlightQuery))
then common:translateSnippet(search:snippet($doc, <cast>{ $highlightQuery }</cast>/*), $outputFormat)
then common:translateSnippet(search:snippet($doc, <cast>{ $highlightQuery }</cast>/*))
else ()

return
Expand Down

0 comments on commit 93b66bd

Please sign in to comment.