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]> 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]> 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]
> Manage your subscription at:
> http://developer.marklogic.com/mailman/listinfo/general
>
>
_______________________________________________
General mailing list
[email protected]
Manage your subscription at: 
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to