Hi Erik, Thanks for the solution. But if the query is case-insensitive, then the map will not work. Any solution for that.
Thanks Pragya From: general-boun...@developer.marklogic.com [mailto:general-boun...@developer.marklogic.com] On Behalf Of Erik Hennum Sent: Friday, September 27, 2013 9:28 PM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Count the occurrences of highlighted text Hi, Pragya: The xdmp:set() call doesn't return the value. The following worked for me: let $terms := ('Google','data','company') let $query := cts:or-query( for $term in $terms return cts:word-query($term) ) let $counts := 0 return cts:highlight($doc,$query, ( xdmp:set($counts,$counts+1), <hit count="{$counts}">{$cts:text}</hit> ) ) If you want to count each term separately, you can use a map: let $terms := ('Google','data','company') let $counts := map:map() let $query := cts:or-query( for $term in $terms return ( map:put($counts,$term,0), cts:word-query($term) ) ) return cts:highlight($doc,$query, ( let $c := map:get($counts,$cts:text)+1 return ( map:put($counts,$cts:text,$c), <hit count="{$c}">{$cts:text}</hit> ) ) ) Hoping that's useful, Erik Hennum ________________________________ From: general-boun...@developer.marklogic.com<mailto:general-boun...@developer.marklogic.com> [general-boun...@developer.marklogic.com] on behalf of Pragya Kapoor [pragya_kap...@infosys.com] Sent: Thursday, September 26, 2013 10:06 PM To: general@developer.marklogic.com<mailto:general@developer.marklogic.com> Subject: [MarkLogic Dev General] Count the occurrences of highlighted text Hi, I have to count the words which are highlighted in the document 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 also count there occurrences in the document So, the output should be like this: <hit count = '10'>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 count = '10'>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 count = '10'>Google </hit> as a privately held <hit count = '2'>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 count = '10'>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 count = '10'>Google </hit>'s core search engine. It offers online productivity software including email (Gmail), an office suite (<hit count = '10'>Google </hit> Drive), and social networking (Google+). Desktop products include applications for web browsing, organizing and editing photos, and instant messaging. The <hit count = '2'>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 count = '10'>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 count = '10'>Google </hit> Fiber broadband service.[15] The corporation has been estimated to run more than one million servers in <hit count = '2'>data </hit> centers around the world[16] and to process over one billion search requests[17] and about 24 petabytes of user-generated <hit count = '2'>data </hit> each day.[18][19][20][21] In December 2012 Alexa listed <hit count = '10'>Google </hit>.com as the most visited website in the world. Numerous <hit count = '10'>Google </hit> sites in other languages figure in the top one hundred, as do several other <hit count = '10'>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] I was trying 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 $count := 0 let $array := ('Google','data','company') let $query1 := for $i in $array return cts:word-query($i) let $query2 := cts:or-query($query1) return if($doc) then cts:highlight($doc,$query2, let $hit := <hit count='{ xdmp:set($count,($count + 1)) }' >{$cts:text}</hit > return $hit) else () But this is not working? 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 General@developer.marklogic.com http://developer.marklogic.com/mailman/listinfo/general