And to clarify one other thing, you can take the string representation of a 
cts:query (for example, cts:word-query("dog")  ) and put it inside an element 
constructor to turn it into the XML representation of a cts:query (the 
schema-element(cts:query) ).  To pass this into search resolve, you can do 
something like:

let $q := <foo>{cts:word-query("dog")}</foo>/cts:query
return
search:resolve($q)

See Chapter 3 of the Search Developer's Guide, "Composing cts:query 
Expressions", the "XML Serialization of cts:query Constructors" subsection for 
a more detailed explanation.

-Danny
________________________________________
From: [email protected] 
[[email protected]] On Behalf Of Justin Makeig 
[[email protected]]
Sent: Monday, February 15, 2010 1:18 PM
To: General Mark Logic Developer Discussion
Subject: Re: [MarkLogic Dev General] re:Query By Example

Bob,
It sounds like you're passing XML to something that's expecting a string. 
Please give this a try:

xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search";
    at "/MarkLogic/appservices/search/search.xqy";
let $q := <cts:and-query xmlns:cts="http://marklogic.com/cts";>
  <cts:element-query>
    <cts:element>MyElementName</cts:element>
    <cts:and-query>
      <cts:element-attribute-value-query>
        <cts:element>MyElementName</cts:element>
        <cts:attribute>MyAttributeName</cts:attribute>
        <cts:text xml:lang="en">text_to_match</cts:text>
      </cts:element-attribute-value-query>
    </cts:and-query>
  </cts:element-query>
</cts:and-query>
return search:resolve($q)

Justin


Justin Makeig
Product Manager
Mark Logic Corporation
999 Skyway Road
Suite 200
San Carlos, CA 94070
+1 650 655 2387 Phone
[email protected]<mailto:[email protected]>
www.marklogic.com<http://www.marklogic.com/> 
<http://www.marklogic.com/><http://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.

On Feb 15, 2010, at 10:52 AM, Runstein, Robert E. (Contr) (IS) wrote:


Hi Justin,

I misstated what I meant.  I encountered a problem in converting my 
cts:and-query to  the “serialized and annotated cts:query” required by 
search:resolve.  I tried to convert it with 
search:parse(xdmp:quote($and-query)), but the resulting cts:and-query is not 
what I would expect.  For example, here is the cts:and-query before parsing:

<cts:and-query xmlns:cts=”http://marklogic.com/cts>

  <cts:element-query>

    <cts:element>MyElementName</cts:element>

    <cts:and-query>

        <cts:element-attribute-value-query>

          <cts:element>MyElementName</cts:element>

                           <cts:attribute>MyAttributeName</cts:attribute>

                           <cts:text xml:lang=”en”>text_to_match</cts:text>

                     </cts:element-attribute-value-query>

          </cts:and-query>

    </cts:element-query>

<cts:and-query>


Here is the (start of) the parsed result:


<cts:and-query strength=”20” xmlns:cts=”http:marklogic.com/cts”>

  <cts:word-query qtextref=”cts:text”>

    <cts:text>cts:and-query(cts:element-query(xs:QName(</cts:text>

  </cts:word-query>

  <cts:and-query strength =”20”>

    <cts:word-query qtextpre=””” qtextref=”cts:text” qtextpost=”””>

        <cts:text>MyElementName</cts:text>

    </cts:word-query>

  <cts:and-query strength=”20”>

    <cts:word-query qtextref=”cts:text”>

      <cts:text>)</cts:text>

    </cts:word-query>

    <cts:word-query qtextref=”cts:text”>

      <cts:text>,</cts:text>

    </cts:word-query>

….

</cts:and-query>

As the above shows, the parsed version seems to be breaking up the original 
query into word queries that contain the text of the cts:queries including 
separate word queries for punctuation within the xs:QName constructor.  
Naturally, I get no results when I pass this to search:resolve.

Attempting to pass the cts:and-query directly to search:resolve results in an 
error stating that it cannot be coerced into an element().  So the question is 
how do I convert my cts:and-query into a schema-element(cts:query)?


Bob

------------------------------------------------------------------------------------------------------------------------

Bob,

As you've indicated, search:search allows you to go end-to-end from a query 
string (e.g. oil OR gas published:yesterday) to to a search:response report 
which includes result snippets, facets, and other features specified in the 
options parameter. search:resolve allows you to bypass the query parsing by 
supplying your own cts:query element rather than a raw query string. I'm not 
quite sure what you mean by "I considered using search:resolve but that 
requires my query to be a string." I can probably better guide you with some 
code to illustrate what you've tried.

Justin

On Feb 15, 2010, at 7:56 AM, Runstein, Robert E. (Contr) (IS) wrote:


Hi All,

I’m building a feature that allows advanced users to specify a query by 
submitting an XML document containing elements and attributes whose values 
specify the element and attribute values that the results should match on.  
Users have the freedom to submit documents containing new elements that they 
want to query on and we want them to be able to do this without our having to 
create new indexes and option constraints each time they add a new element.  I 
call this query by example.

I’ve done this by creating  a cts:element-query for each element.  The query 
wraps a cts:and-query of the element’s text (if any) as a cts:word-query and 
each attribute’s text as a cts:element-attribute-value-query.  The resulting 
cts:element-querys are combined in a cts:and-query.

The issue that I’m having is that I want to do a search:search to get a 
search:response rather than a cts:search that gives me the full content of the 
matching documents.  I can achieve this by including my cts:and-query as an 
additional-query within my search:options and leaving the qtext empty.

I considered using search:resolve but that requires my query to be a string.  I 
tried using xmdp:quote and search:parse on my cts:and-query, but that just 
mangles the query and does not return results.

Is including my generated query as an additional-query to search:search options 
the best way to do this or is there a way to convert my cts:and-query to a 
string for search:resolve that won’t mangle it, or is there a better approach 
to implementing query by example than the path I have followed?


Thanks.

Bob

_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://xqzone.com/mailman/listinfo/general

_______________________________________________
General mailing list
[email protected]
http://xqzone.com/mailman/listinfo/general

Reply via email to