Gary ,
Thanks for the solution.
Is there any way by which I can sort the map?
I am trying the below code and the sorting is not happening.
for $term in map:keys($terms) order by fn:string-length($term)
return fn:string-length($term)
I want to sort the map keys in length order.
My complete code is this:
let $doc := <p> Google Inc. is an American multinational corporation
specializing in Internet-related services and products. These include search,
cloud computing, software and online advertising technologies.[7] Most of its
profits are derived from AdWords.[8][9]
Google was founded by Larry Page and Sergey Brin while they were Ph.D. students
at Stanford University. Together they own about 16 percent of its shares. They
incorporated Google as a privately held company on September 4, 1998. An
initial public offering followed on August 19, 2004. Its mission statement from
the outset was "to organize the world's information and make it universally
accessible and useful",[10] and its unofficial slogan was "Don't be
evil".[11][12] In 2006 Google moved to headquarters in Mountain View,
California, nicknamed the Googleplex.
Rapid growth since incorporation has triggered a chain of products,
acquisitions and partnerships beyond Google's core search engine. It offers
online productivity software including email (Gmail), an office suite (Google
Drive), and social networking (Google+). Desktop products include applications
for web browsing, organizing and editing photos, and instant messaging. The
company leads the development of the Android mobile operating system and the
browser-only Chrome OS[13] for a specialized type of netbook known as a
Chromebook. Google has moved increasingly into communications hardware: it
partners with major electronics manufacturers in production of its high-end
Nexus devices and acquired Motorola Mobility in May 2012.[14] In 2012, a
fiber-optic infrastructure was installed in Kansas City to facilitate a Google
Fiber broadband service.[15]
The corporation has been estimated to run more than one million servers in data
centers around the world[16] and to process over one billion search
requests[17] and about 24 petabytes of user-generated data each
day.[18][19][20][21] In December 2012 Alexa listed google.com as the most
visited website in the world. Numerous Google sites in other languages figure
in the top one hundred, as do several other Google-owned sites such as YouTube
and Blogger.[22] Its market dominance has led to criticism over issues
including copyright, censorship, and privacy.[23][24]
</p>
let $customTerms as xs:string* := "google@red;multinational@white;google
Inc@yellow;"
let $doc:=
if($customTerms eq "") then $doc
else
let $tempTerms := fn:tokenize($customTerms,';')
let $tempDoc :=
for $tempTerm in $tempTerms
let $temp := fn:tokenize($tempTerm,'@')
(: extracting the custom terms :)
let $term as xs:string* := for $j in $temp[1] return
fn:lower-case($j)
(: extracting the color :)
let $color := $temp[2]
let $count := fn:count($term)
(: Putting the custom terms in map :)
let $terms :=
let $map := map:map()
return (
for $i in $count return
map:put($map,$term[$i],$color[$i]),
$map
)
(: Creating OR query with custom terms :)
let $query := cts:or-query(
for $term in map:keys($terms)
return
cts:word-query($term,('case-insensitive','unstemmed','wildcarded'))
)
(: Highlisting the custom terms :)
let $doc1 := cts:highlight($doc,$query,
if(fn:exists($cts:node/ancestor-or-self::custom_term))
then $cts:text else
<custom_term>{
let $color :=
map:get($terms,fn:lower-case($cts:text))
return
if (fn:empty($color)) then ()
else attribute color {$color},
$cts:text
}</custom_term>
)
let $sset := xdmp:set($doc,$doc1)
return $doc
return
$tempDoc[fn:last()]
return $doc
Thanks
Pragya
-----Original Message-----
From: [email protected]
[mailto:[email protected]] On Behalf Of Gary Vidal
Sent: Wednesday, November 20, 2013 5:00 PM
To: [email protected]
Subject: Re: [MarkLogic Dev General] Highlighting query
Pragya,
If you want full phrase matches where longest string match wins then you will
probably want to sort each term in length order and iterate over each phrase or
word and highlight like noted except with may just constructed elements. But
he order in which you execute them will be the difference. So if you highlight
terms longest to shortest then you have better chance to match longer terms
over shorter terms.
In your highlight function you may want to check if the node you are
highlighting has already been highlighted by looking at the cts:node variable
and stepping up the ancestor path like below.
if(fn:exists($cts:node/ancestor-or-self::html:span)) then
<html:span>{$cts:text}</html:span> else $cts:text
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general
**************** CAUTION - Disclaimer *****************
This e-mail contains PRIVILEGED AND CONFIDENTIAL INFORMATION intended solely
for the use of the addressee(s). If you are not the intended recipient, please
notify the sender by e-mail and delete the original message. Further, you are
not
to copy, disclose, or distribute this e-mail or its contents to any other
person and
any such actions are unlawful. This e-mail may contain viruses. Infosys has
taken
every reasonable precaution to minimize this risk, but is not liable for any
damage
you may sustain as a result of any virus in this e-mail. You should carry out
your
own virus checks before opening the e-mail or attachment. Infosys reserves the
right to monitor and review the content of all messages sent to or from this
e-mail
address. Messages sent to or from this e-mail address may be stored on the
Infosys e-mail system.
***INFOSYS******** End of Disclaimer ********INFOSYS***
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general