Hi Erik,
Thanks for the solution.
I modified the solution to cater my requirements but the result contains 3
documents instead of one and the last document has all the terms highlighted.
i.e the number of terms we have the document is repeated that number of times
in the result with last document having all terms highlighted.
let $terms1:= fn:lower-case('Google:red;company:blue;data:black')
let $temp := fn:tokenize($terms1,';')
for $i in $temp
let $temp := fn:tokenize($i,':')
let $color := $temp[2]
let $term := $temp[1]
let $count := fn:count($term)
let $terms :=
let $map := map:map()
return (
for $x in $count return
map:put($map,$term[$x],$color[$x]),
$map
)
let $query := cts:or-query(
for $term in map:keys($terms)
return cts:word-query($term,('case-insensitive','unstemmed'))
)
let $doc1 := cts:highlight($doc,$query,
<hit>{
let $color := map:get($terms,fn:lower-case($cts:text))
return
if (empty($color)) then ()
else attribute color {$color},
$cts:text
}</hit>
)
let $sset := xdmp:set($doc,$doc1)
return $doc
Please help on this . So that I return only one document with all terms
highlighted.
Thanks
Pragya
From: [email protected]
[mailto:[email protected]] On Behalf Of Erik Hennum
Sent: Friday, October 11, 2013 5:23 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Highlighting query
Hi, Pragya:
Would something similar to the following fragment (untested) meet the
requirements?
let $terms :=
let $map := map:map()
return (
map:put($map,'Google','1'),
map:put($map,'company','4'),
map:put($map,'data','7'),
$map
)
let $query := cts:or-query(
for $term in map:keys($terms)
return cts:word-query($term)
)
return cts:highlight($doc,$query,
<hit>{
let $color := map:get($terms,$cts:text)
return
if (empty($color)) then ()
else attribute color {$color},
$cts:text
}</hit>
)
Hoping that helps,
Erik Hennum
________________________________
From:
[email protected]<mailto:[email protected]>
[[email protected]] on behalf of Pragya Kapoor
[[email protected]]
Sent: Thursday, October 10, 2013 10:47 PM
To: [email protected]<mailto:[email protected]>
Subject: [MarkLogic Dev General] Highlighting query
Hi,
I have to highlighted the terms in the document and with terms and need to tag
them with number provided in request.
EG: terms will have values like Google:1,data:7,company:4
So while doing highlighting I need to attach the attribute color having values
as 1, 7,4...
EG:
Document has :
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]
Customized highlighting terms : Google,data,company
Now I need to highlight these terms and tag the numbers to those tags
Output should be like this:
<hit color = '1'>Google </hit> 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]
<hit color = '1'>Google </hit> 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 <hit color = '1'>Google </hit> as a
privately held <hit color = '4'>company </hit> 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 <hit color = '1'>Google </hit> moved to headquarters in
Mountain View, California, nicknamed the Googleplex.
Rapid growth since incorporation has triggered a chain of products,
acquisitions and partnerships beyond <hit color = '1'>Google </hit>'s core
search engine. It offers online productivity software including email (Gmail),
an office suite (<hit color = '1'>Google </hit> Drive), and social networking
(Google+). Desktop products include applications for web browsing, organizing
and editing photos, and instant messaging. The <hit color = '4'>company </hit>
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. <hit color = '1'>Google </hit> 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 <hit color = '1'>Google </hit> Fiber broadband service.[15]
The corporation has been estimated to run more than one million servers in <hit
color = '7'>data </hit> centers around the world[16] and to process over one
billion search requests[17] and about 24 petabytes of user-generated <hit color
= '7'>data </hit> each day.[18][19][20][21] In December 2012 Alexa listed <hit
color = '1'>Google </hit>.com as the most visited website in the world.
Numerous <hit color = '1'>Google </hit> sites in other languages figure in the
top one hundred, as do several other <hit color = '1'>Google </hit>-owned sites
such as YouTube and Blogger.[22] Its market dominance has led to criticism over
issues including copyright, censorship, and privacy.[23][24]
Please let me know, how can I achieve this?
Thanks
Pragya
**************** 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