Thanks for the reply. But I have further queries: Q1. I have large dataset so I can't go with word lexion. So now how do I solve this problem? I was trying to create a custom constraint using parse function but still I am not getting any suggestions. Files used: Suggestion source.xqy:
import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; import module namespace suggestion ="suggestion-namespace" at "/suggestion_parse.xqy"; let $options := <options xmlns="http://marklogic.com/appservices/search"> <constraint name="test"> <custom facet="false"> <parse apply="test" ns="suggestion-namespace" at = "/suggestion_parse.xqy"/> </custom> </constraint> <suggestion-source ref ="test"> <custom facet="false"> <parse apply="test" ns="suggestion-namespace" at="/suggestion_parse.xqy"/> </custom> </suggestion-source> <debug>true</debug> </options> let $suggestions := search:suggest("test:A", $options) return $suggestions suggestion_parse.xqy is below: xquery version "1.0-ml"; module namespace suggestion ="suggestion-namespace"; declare function test($constraint-qtext as xs:string, $right as schema-element(cts:query)) as schema-element(cts:query){ let $s := $right//cts:text/text() let $query := cts:element-word-query(xs:QName("CaseName"),$s) let $dummy := xdmp:log ("In Parse function","error") return <cts:query>{$query}</cts:query> }; Please let me know, if I am missing something in these two files. Q2. Yes, I am doing it so because its easy to generate json this way.Here my requirement is to get suggestions in json format. Is there any other way of getting json which will be in the alphabetical order of suggestions. Please let me know with some sample code. Q3 thanks for the code. Its working for me. Thanks, Pragya -----Original Message----- From: [email protected] [mailto:[email protected]] On Behalf Of [email protected] Sent: Wednesday, May 12, 2010 12:30 AM To: [email protected] Subject: General Digest, Vol 71, Issue 19 Send General mailing list submissions to [email protected] To subscribe or unsubscribe via the World Wide Web, visit http://developer.marklogic.com/mailman/listinfo/general or, via email, send a message with subject or body 'help' to [email protected] You can reach the person managing the list at [email protected] When replying, please edit your Subject line so it is more specific than "Re: Contents of General digest..." Today's Topics: 1. extracting the parent element id for each suggestion (Pragya Kapoor) 2. Re: Search suggestion Query (Colleen Whitney) ---------------------------------------------------------------------- Message: 1 Date: Tue, 11 May 2010 15:27:46 +0530 From: Pragya Kapoor <[email protected]> Subject: [MarkLogic Dev General] extracting the parent element id for each suggestion To: "[email protected]" <[email protected]> Message-ID: <619edcf9bde87d48a4ad619d8580024e0432210...@blrkecmbx05.ad.infosys.com> Content-Type: text/plain; charset="us-ascii" Hi, Is it possible to extract the parent element id for each suggestion? If yes how? e.g: <wl:entry id="123456" priority="123456789"> <wl:title>Donoghue v Stevenson</wl:title> /wl:entry> wl:title is the element used for suggestions I am using following code for getting suggestions: let $options := <search:options xmlns="http://marklogic.com/appservices/search"> <default-suggestion-source> <range collation="http://marklogic.com/collation/" type="xs:string" facet="true"> <element ns="" name="title"/> </range> </default-suggestion-source> </search:options> let $suggestion := search:suggest($query, $options) let $suggestionsMap := map:map() let $populateMap := for $suggestion at $index in $suggestions return map:put($suggestionsMap, fn:concat("suggestion", $index), $suggestion) let $json-response := xdmp:to-json($suggestionsMap) return fn:concat('{"Suggestions":', $json-response,"}") Please send sample code for implementing the same. Thanks, Pragya -------------- next part -------------- An HTML attachment was scrubbed... URL: http://developer.marklogic.com/pipermail/general/attachments/20100511/a4f07854/attachment-0001.html ------------------------------ Message: 2 Date: Tue, 11 May 2010 09:57:40 -0700 From: Colleen Whitney <[email protected]> Subject: Re: [MarkLogic Dev General] Search suggestion Query To: General Mark Logic Developer Discussion <[email protected]>, "[email protected]" <[email protected]> Message-ID: <[email protected]> Content-Type: text/plain; charset="Windows-1252" Hi Pragya, I'll try to answer one question at a time. 1. Yes, search:suggest() matches from the first word starting from the left, using the *value* of the term in the range index, not the *words* in the range index. So given the configuration you have, the term "finance" will not generate a suggestion from "Municipal Finance Authority Act". One alternative to keep in mind, if your dataset is not too large, is to build a field on that element, add a word lexicon to that field, and then use the field to generate suggestions. There are some things to keep in mind if you do that: word lexicons don't scale as well as range indexes, so as your dataset grows you'll see slower performance. And since every token in a string will be used for suggestions, you might find that the suggestions don't look as clean. Again, depending on your data and your application, you could consider adding metadata elements to your documents that contain key terms, and using them to generate suggestions. 2. I don't recommending putting the terms into a map as you've done in your code; any order is lost that way. Are you doing it so that it's easy to generate json? For ordering, it's easier to use a <suggestion-option> element to indicate how you want the terms to be ordered. You can specify ascending or descending (and that order will depend on the collation of your range index); you can also specify whether you want your terms to be in frequency order (most frequently occurring) or in item order (ordered by datatype, which is alphabetical for strings). Here's an example of how you would use a suggestion option to specify the ordering of suggestions from the "color" constraint. Notice that that suggestion-source node references the "color" constraint; only terms starting with "color:" are affected by those options. You can also use suggestion-options with default-suggestion-source, to affect all unconstrained terms. <options xmlns="http://marklogic.com/appservices/search"> <constraint name="color"> <range type="xs:string"> <element ns="" name="bodycolor"/> </range> </constraint> <suggestion-source ref="color"> <suggestion-option>item-order</suggestion-option> <suggestion-option>descending</suggestion-option> </suggestion-source> <constraint name="texture"> <range type="xs:string"> <element ns="" name="texture"/> </range> </constraint> <suggestion-source ref="texture"/> <default-suggestion-source> <range type="xs:string" collation="http://marklogic.com/collation/en/S4/EO/CU/MO"> <element ns="http://widgets-r-us.com" name="clean-queries"/> </range> <suggestion-option>item-order</suggestion-option> </default-suggestion-source> </options> 3. Every suggestion-source element must refer to an existing constraint. They are used to specify how to generate suggestions for a specific constraint (or to disable them, as in the "texture" example above). So if you use that sample configuration, and type "texture:", suggestions are not generated from the range index. The default-suggestion-source is used for any terms that are not associated with a constraint. So in the example above, if you type "color:f", then suggestions are generated from the "bodycolor" element; but if you type "f" suggestions come from the "clean-queries" element in the http://widgets-r-us.com namespace. I know it's a little complicated to configure, but it's pretty powerful; it essentially means that facets and suggestions can work together. I hope this helps... --Colleen ________________________________________ From: [email protected] [[email protected]] On Behalf Of Pragya Kapoor [[email protected]] Sent: Monday, May 10, 2010 10:30 PM To: [email protected]; [email protected] Subject: [MarkLogic Dev General] Search suggestion Query Hi, I have following queries regarding search suggestions. I am using version 4.1 1. In search suggest, using default-suggestion-source ML matches from the first word in the string starting from left. Eg: 'Municipal Finance Authority Act'(DATA) Search string: m or Municipal (suggestions are coming) But if search string is : finance(no suggestions come)---- How to achieve this? I am using the below options in search suggest: let $options := <search:options xmlns="http://marklogic.com/appservices/search"> <constraint name="CaseName"> <range collation="http://marklogic.com/collation" type="xs:string" facet="true"> <element ns="" name="CaseName"/> </range> </constraint> <default-suggestion-source> <range collation="http://marklogic.com/collation/" type="xs:string" facet="true"> <element ns="" name="CaseName"/> </range> </default-suggestion-source> </search:options> let $suggestions:= search:suggest((?a?),$options) Also, I tired creating a custom constraint using parse function but still I am not getting any suggestions. PFA files used Please let me know, if I am missing something. 2. I get the response as follows: {"Suggestions":{"suggestion3":"\"Austin v The Commissioner of Police of the Metropolis\"", "suggestion2":"\"Austin and another v Metropolitan Police Commissioner\"", "suggestion1":"\"AB and others v Ministry of Defence\""}} But I want to order them as: suggestion1 suggestion2 suggestion3 or alphabetical order of suggestions. So what needs to be added below to achieve this: let $suggestions := search:suggest(("A"), $options) let $suggestionsMap := map:map() let $populateMap := for $suggestion at $index in $suggestions return map:put($suggestionsMap, fn:concat("suggestion", $index), $suggestion) let $json-response := xdmp:to-json($suggestionsMap) return fn:concat('{"Suggestions":', $json-response,"}") Or if there is some other way of doing the same .Please provide some sample code. 3. I am unable to use <suggestion-source>option in place of </default-suggestion-source>.Could you please let me know exactly how to use this. And also how to use multiple <suggestion-source>.One working code will help us a lot. 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 End of General Digest, Vol 71, Issue 19 *************************************** _______________________________________________ General mailing list [email protected] http://developer.marklogic.com/mailman/listinfo/general
