That was by mistake. It had to be "can I have a word with you" in the xml also. 
I have made the change in xml and have attached it in the mail.

-----Original Message-----
From: [email protected] 
[mailto:[email protected]] On Behalf Of Michael Blakeley
Sent: Wednesday, June 20, 2012 9:50 PM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] cts:search and xdmp:save()

This time the query seems to be:

    let $search := 'can i have a word with you?'

But I see no matches for that string in the XML. The closest match in the XML 
seems to be:

        <wl:head>can i have a word with u?</wl:head>

-- Mike

On 20 Jun 2012, at 00:13 , Yeshmeet Singh wrote:

> Hi,
> 
> I tried adding the unwildcarded option but it is still not working. I am 
> attaching my query and the sample data on which I am running my query. Please 
> let me know if anything can be done to bring up results containing "?" in 
> them.
> 
> Thanks
> Yashmeet
> 
> -----Original Message-----
> From: [email protected] 
> [mailto:[email protected]] On Behalf Of Michael 
> Blakeley
> Sent: Tuesday, June 19, 2012 8:59 PM
> To: MarkLogic Developer Discussion
> Subject: Re: [MarkLogic Dev General] cts:search and xdmp:save()
> 
> Understandable, I think. The sample code is hard to read, and won't parse or 
> run in its current form. But Mary has powerful ESP.
> 
> Here's a test case that shows what I think Mary has in mind. Punctuation in 
> the query text could be punctuation or could be a wildcard. Since the term is 
> punctuation-insensitive, it is treated as a wildcard. The wildcard will be 
> looking for a word character, not a punctuation character, the term fails to 
> match anything. The second two forms show possible fixes: be explicit about 
> no wildcards, or be punctuation-sensitive.
> 
> (: punctuation-insensitive, implicit wildcard :) cts:contains(  
> element test { "EPL and Fixtures: Are the fixtures out?" },  
> cts:element-value-query(
>    xs:QName('test'),
>    "EPL and Fixtures: Are the fixtures out?",
>    ("case-insensitive",
>     "diacritic-sensitive",
>     "punctuation-insensitive",
>     "unstemmed",
>     "lang=en"))),
> (: explicitly not a wildcard :)
> cts:contains(
>  element test { "EPL and Fixtures: Are the fixtures out?" },  
> cts:element-value-query(
>    xs:QName('test'),
>    "EPL and Fixtures: Are the fixtures out?",
>    ('unwildcarded',
>     "case-insensitive",
>     "diacritic-sensitive",
>     "punctuation-insensitive",
>     "unstemmed",
>     "lang=en"))),
> (: default wildcard, punctuation-sensitive :) cts:contains(  element 
> test { "EPL and Fixtures: Are the fixtures out?" },  
> cts:element-value-query(
>    xs:QName('test'),
>    "EPL and Fixtures: Are the fixtures out?",
>    ("case-insensitive",
>     "diacritic-sensitive",
>     "punctuation-sensitive",
>     "unstemmed",
>     "lang=en")))
> =>
> false
> true
> true
> 
> -- Mike
> 
> On 19 Jun 2012, at 07:20 , David Lee wrote:
> 
>> This is confusing to me.
>> From my read of this, the "?" is in the data not the query ... so how is 
>> wildcarded or not affect this ?
>> 
>> ---------------------------------------------------------------------
>> -
>> -------
>> David Lee
>> Lead Engineer
>> MarkLogic Corporation
>> [email protected]
>> Phone: +1 650-287-2531
>> Cell:  +1 812-630-7622
>> www.marklogic.com
>> 
>> This e-mail and any accompanying attachments are confidential. The 
>> information is intended solely for the use of the individual to whom it is 
>> addressed. Any review, disclosure, copying, distribution, or use of this 
>> e-mail communication by others is strictly prohibited. If you are not the 
>> intended recipient, please notify us immediately by returning this message 
>> to the sender and delete all copies. Thank you for your cooperation.
>> 
>> From: [email protected]
>> [mailto:[email protected]] On Behalf Of Mary 
>> Holstege
>> Sent: Tuesday, June 19, 2012 10:13 AM
>> To: MarkLogic Developer Discussion
>> Subject: Re: [MarkLogic Dev General] cts:search and xdmp:save()
>> 
>> Try adding an explicit unwilcarded option. Question mark is a wildcard 
>> character, so you are looking for something that matches that word with one 
>> more character at the end.
>> 
>> Sent from my Samsung Epic(tm) 4G
>> 
>> 
>> Yeshmeet Singh <[email protected]> wrote:
>> 
>> 
>> Hi,
>> 
>> I am having some trouble with the cts:search. I have an application 
>> in which when a user enters a search term I take that term and search 
>> it through the marklogic collections and return the result. Now what 
>> problem I am facing is that in the database in my xml file I have a 
>> tag called <head>, now if in this head if I have any statement that 
>> has a "?" in it it is not being returned by the cts:search. For 
>> example if I search for a term say "EPL and Fixtures" what I do first 
>> is create a cts:element-value-match query to search the database 
>> first and store that query in a variable which gives me the following
>> output-
>> 
>> Let $t := <v:results v:warning="non-element item"><cts:and-query> 
>> <cts:or-query><cts:element-value-query>
>> <cts:element>_1:head</cts:element>
>> <cts:text xml:lang="en">EPL and Fixtures: Are the fixtures 
>> out?</cts:text> <cts:option>case-insensitive</cts:option>
>> <cts:option>diacritic-sensitive</cts:option>
>> <cts:option>punctuation-insensitive</cts:option>
>> <cts:option>unstemmed</cts:option>
>> </cts:element-value-query>
>> <cts:element-value-query>
>> <cts:element>_1:head</cts:element>
>> <cts:text xml:lang="en">Fixtures and the EPL 2009: 
>> Champion?</cts:text> <cts:option>case-insensitive</cts:option>
>> <cts:option>diacritic-sensitive</cts:option>
>> <cts:option>punctuation-insensitive</cts:option>
>> <cts:option>unstemmed</cts:option>
>> </cts:element-value-query>
>> </cts:or-query>
>> <cts:element-word-query>
>> <cts:element>_1:head</cts:element>
>> <cts:textxml:lang="en">EPL</cts:text>
>> <cts:option>case-insensitive</cts:option>
>> <cts:option>diacritic-sensitive</cts:option>
>> <cts:option>punctuation-insensitive</cts:option>
>> <cts:option>unstemmed</cts:option>
>> </cts:element-word-query>
>> <cts:or-query>
>> <cts:element-word-query>
>> <cts:element>_1:head</cts:element>
>> <cts:textxml:lang="en">Fixtures</cts:text>
>> <cts:option>case-insensitive</cts:option>
>> <cts:option>diacritic-sensitive</cts:option>
>> <cts:option>punctuation-insensitive</cts:option>
>> <cts:option>unstemmed</cts:option>
>> </cts:element-word-query>
>> <cts:element-word-query>
>> <cts:element>_1:head</cts:element>
>> <cts:textxml:lang="en">Fixtures*</cts:text>
>> <cts:option>case-insensitive</cts:option>
>> <cts:option>diacritic-sensitive</cts:option>
>> <cts:option>punctuation-insensitive</cts:option>
>> <cts:option>unstemmed</cts:option>
>> </cts:element-word-query>
>> </cts:or-query>
>> <cts:collection-query>
>> <cts:uri>dictionaryid </cts:uri>
>> </cts:collection-query>
>> <cts:collection-query><cts:uri>dictionarystatus</cts:uri>
>> </cts:collection-query>
>> </cts:and-query>
>> </v:results>
>> 
>> Now I make a call to my cts search-
>> Let result := cts:search(/wl:start, $t)
>> 
>> The above does not return any result. And this is happening only for those 
>> terms in my <head> tag that have "?".
>> 
>> Also I wanted to write the output of my xqy file into an xml file. Using 
>> xdmp:save() we can create a text file. Is there any way to create an xml 
>> file?
>> 
>> Thanks
>> Yashmeet Singh
>> 
>> **************** 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://community.marklogic.com/mailman/listinfo/general
> 
> _______________________________________________
> General mailing list
> [email protected]
> http://community.marklogic.com/mailman/listinfo/general
> <test_data.xml><query.txt>____________________________________________
> ___
> General mailing list
> [email protected]
> http://community.marklogic.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://community.marklogic.com/mailman/listinfo/general
<?xml version="1.0" encoding="utf-8" standalone="no"?>

 <wl:body>
    <wl:entries>
      <wl:data id="1" priority="1">
        <wl:head>keep playing</wl:head>
      </wl:data>
      <wl:data id="2" priority="1">
        <wl:head>Can you please clear the table?</wl:head>
      </wl:data>
      <wl:data id="3" priority="1">
        <wl:head>Dormer</wl:head>
        
      </wl:data>
      <wl:data id="4" priority="1">
        <wl:head>can i have a word with you?</wl:head>
        
      </wl:data>
      <wl:data id="5" priority="1">
        <wl:head>you can go to play</wl:head>
        
      </wl:data>
      <wl:data id="6" priority="1">
        <wl:head>where is every one?</wl:head>
        
      </wl:data>
      <wl:data id="7" priority="1">
        <wl:head>Shutt</wl:head>
      </wl:data>
</wl:entries>
</wl:body>
Following is the piece of code i am trying to run:

let $search := 'can i have a word with you?'
let $suggestLimit := 10
let $otions :=(
      <cts:option 
xmlns:cts="http://marklogic.com/cts";>punctuation-insensitive</cts:option>
      <cts:option 
xmlns:cts="http://marklogic.com/cts";>case-insensitive</cts:option>
      <cts:option 
xmlns:cts="http://marklogic.com/cts";>diacritic-sensitive</cts:option>
      <cts:option xmlns:cts="http://marklogic.com/cts";>unstemmed</cts:option>
        )
let $stripped :=xdmp:apply(xdmp:function(xs:QName(function path)(used to remove 
some noise words)
(:this return us-$stripped :='can i have word with you?':)

let $elem := fn:QName('namespace', 'head')
let $title-query := 
            cts:query(lex:build-lexicon-based-query($search, $stripped, $elem, 
$dictionaryId, $suggestLimit))

(:this is my build-lexicon-based-query function:)
declare function lex:build-lexicon-based-query(
    $original as xs:string,
    $stripped as xs:string+, 
    $elem as xs:QName,    
    $dictionaries as xs:string+, 
    $limit as xs:integer,
     {
    let $matches := lex:get-strings($original, $stripped, $elem, $restriction, 
$limit,      $profile)
        return
      element cts:and-query {
        element cts:or-query {
            for $title in $matches
            return 
                element cts:element-value-query { 
                    element cts:element  { $elem }, 
                    element cts:text { $title }, 
                    $options) 
                }
        },
        ()
    }
    
    
};

(:following is my lex:get-string function:)
declare function lex:get-strings(
    $original as xs:string,
    $stripped as xs:string,
    $elem as xs:QName,
    $limit as xs:integer,
     {

    
    let $qtokens := fn:tokenize($stripped, ' ')          
    let $options := if(functx:get-matches($qtokens[fn:last()], '\d+$')) then 
                        
($options,"collation=http://marklogic.com/collation/en/S1/AS/T0020";)
                 else $options
    return
    
    if(fn:count($qtokens) = 1)
    then
        let $count := 0
        let $first-pass := 
        if ($original ne $stripped) then                 
            (cts:element-value-match($elem, $original, $options),
             cts:element-value-match($elem, $stripped, $options))
        else    
            cts:element-value-match($elem, $original, $options)             
        let $first-pass :=  ($first-pass,cts:element-value-match($elem, 
fn:concat($qtokens, '*'), $options))
        let $count := fn:count($first-pass)
        let $second-pass := 
            if($count lt $limit) then
             fn:distinct-values(($first-pass,
                     cts:element-value-match($elem, fn:concat($qtokens, "* *"), 
$options)))

            else ()
        let $count := fn:count($second-pass)
        let $third-pass := 
            if($count lt $limit) then
            fn:distinct-values(($first-pass,$second-pass,
                cts:element-value-match($elem, fn:concat("*",$stripped,"*"), 
$options)))
            else ()
        let $count := fn:count($third-pass)
        let $fourth-pass :=  
            if($count lt $limit) then
            fn:distinct-values(($first-pass,$second-pass,$third-pass,
                cts:element-value-match($elem, fn:concat("*",$original,"* *"), 
$options)))
            else () 

        return 
fn:distinct-values(($first-pass,$second-pass,$third-pass,$fourth-pass))

    else
        let $count := 0
        let $first-pass := (cts:element-value-match($elem, $original, $options),
                           cts:element-value-match($elem, fn:concat($original, 
'*'), $options),
                           cts:element-value-match($elem, fn:concat($stripped, 
'*'), $options))
        let $count := fn:count($first-pass)
        let $second-pass := 
            if($count lt $limit) then
             fn:distinct-values(($first-pass,
             (if($original ne $stripped) then
                     (cts:element-value-match($elem, fn:concat('* ',$original, 
' *'), $options),
                     cts:element-value-match($elem, fn:concat('* ',$stripped, ' 
*'), $options))
             else 
        cts:element-value-match($elem, fn:concat('* ',$original, ' *'), 
$options))))

            else ()
        let $count := fn:count($second-pass)
        let $third-pass := 
            if($count lt $limit) then
            let $third := fn:string-join(
                            for $term in $qtokens[1 to fn:last()-1]
                            return
                            fn:concat('* ', $term, '*'), ' '
                          )
            let $third := fn:concat($third,' ',(fn:concat('* 
',$qtokens[fn:last()], '* *')))
            return
            fn:distinct-values(($first-pass,$second-pass,
                                cts:element-value-match($elem,$third, 
$options)))
            else ()
        let $count := fn:count($third-pass)
        let $fourth-pass :=  
            if($count lt $limit) then

            fn:distinct-values(($first-pass,$second-pass,$third-pass,
                                for $term in $qtokens
                                return (                                        
                        cts:element-value-match($elem, fn:concat('* ', $term, ' 
*'), $options))
                               ))

            else ()  
        let $count := fn:count($fourth-pass)
        let $fifth-pass :=  
            if($count lt $limit) then
            
fn:distinct-values(($first-pass,$second-pass,$third-pass,$fourth-pass,
                                for $term in $qtokens
                                return (                
                                cts:element-value-match($elem, fn:concat('* ', 
$term, '* *'), $options)
                                )
                               ))

            else ()                   

         return 
fn:distinct-values(($first-pass,$second-pass,$third-pass,$fourth-pass,$fifth-pass))
       
};

(:Now once i get my results in $title-query i pass that through cts:search)
let $results := 
            rslt:build-results(
            (cts:search(/wl:data, $title-query)[1 to $constant:FILTERLIMIT])

As i wrote i my mail i am getting results in $title-query but when i pass it 
through cts:search no results come up.
_______________________________________________
General mailing list
[email protected]
http://community.marklogic.com/mailman/listinfo/general

Reply via email to