Hi Danny, You may check with the following code if its fit for your requirement.
xquery version "1.0-ml"; declare namespace html = "http://www.w3.org/1999/xhtml"; import module namespace search="http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; declare variable $OPTIONS := <options xmlns="http://marklogic.com/appservices/search"> <values name="author-path"> <range type="xs:string"> <path-index>/contrib-group/contrib[@contrib-type='author']/author-name-string</path-index> </range> </values> <return-values>true</return-values> </options> ; let $options := <options xmlns="http://marklogic.com/appservices/search"> {$OPTIONS/*} </options> let $results := search:search("*Ph.D.", $options) return $results By Raja From: [email protected] [mailto:[email protected]] On Behalf Of Indrajeet Verma Sent: Wednesday, April 22, 2015 11:50 AM To: MarkLogic Developer Discussion Subject: Re: [MarkLogic Dev General] Wildcarded author search Hi Danny, I am not sure if below query fits in your requirement however see if this can. You can create your search:query based on your need and also enhance $options declare variable $OPTIONS := <options xmlns="http://marklogic.com/appservices/search"> <values name="author-path"> <range type="xs:string"> <path-index>/contrib-group/contrib[@contrib-type='author']/author-name-string</path-index> </range> </values> <return-values>true</return-values> </options> ; let $options := <options xmlns="http://marklogic.com/appservices/search"> {$OPTIONS/*} </options> let $results := search:values('author-path', $options, search:parse("John", (), "search:query")) return $results Regards, Indrajeet On Wed, Apr 22, 2015 at 7:37 AM, Danny Sinang <[email protected]<mailto:[email protected]>> wrote: I came up with the solution below. Maybe someone else here has a better approach. let $path := "/contrib-group/contrib[@contrib-type='author']/author-name-string" let $collation := "http://marklogic.com/collation/en/S2" let $options := ("type=string", "collation=" || $collation) let $ref := cts:path-reference($path, $options) let $value-matches := let $matches := cts:value-match ($ref, $author) return if ($matches) then $matches else "" return cts:path-range-query ($path, "=", $value-matches, "collation=" || $collation) On Tue, Apr 21, 2015 at 8:39 PM, Danny Sinang <[email protected]<mailto:[email protected]>> wrote: We've got article authors stored like this : <contrib-group> <contrib contrib-type="author" > <author-name-string>John Baker, Ph.D.</author-name-string> </contrib> <contrib contrib-type="author" > <author-name-string>Sarah Reynolds, Ph.D.</author-name-string> </contrib> </contrib-group> And we'd like the following search strings match the first contrib node above : 1. john* 2. john Bak* 3. *Baker* And we'd like this search string match both both contrib nodes above : *Ph.D. My questions are : 1. What database index settings do I need to set (e.g. trailing wildcard, etc) ? 2. What kind of indexes do I need to make ? 3. What search API options do I need to create ? 4. If I need to create a custom constraint that returns a cts query, what cts query option should I use ? I've tried creating custom constraints that return either cts:element-value-query or cts:element-word-query but I seem to be getting false positives. For example, if I search for john ba*, I get articles with authors named John (some other surname), or Brian Bass. Regards, Danny _______________________________________________ General mailing list [email protected]<mailto:[email protected]> Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general This e-mail and any files transmitted with it are for the sole use of the intended recipient(s) and may contain confidential and privileged information. If you are not the intended recipient(s), please reply to the sender and destroy all copies of the original message. Any unauthorized review, use, disclosure, dissemination, forwarding, printing or copying of this email, and/or any action taken in reliance on the contents of this e-mail is strictly prohibited and may be unlawful. Where permitted by applicable law, this e-mail and other e-mail communications sent to and from Cognizant e-mail addresses may be monitored.
_______________________________________________ General mailing list [email protected] Manage your subscription at: http://developer.marklogic.com/mailman/listinfo/general
