The default search grammar (tip:  use search:default-options() to see those) 
uses parentheses for grouping, e.g. "(cat AND dog) OR cow".  You've got square 
brackets, so those are being parsed as literals with your terms.  I don't see 
the brackets in the tutorial on a quick scan...but if you can tell me which 
section to look in, I'll see about getting that fixed.

And for quoted phrases (which I think might also be of interest to you here), 
by default you use double quotes, e.g. 'title:"The Sound and The Fury" or 
title:"As I Lay Dying"', but you can change that if you customize the grammar 
in your options.

--Colleen

________________________________
From: [email protected] 
[[email protected]] on behalf of Timothy W. Cook 
[[email protected]]
Sent: Friday, December 13, 2013 9:28 AM
To: MarkLogic Developer Discussion
Subject: Re: [MarkLogic Dev General] Search API Syntax?


On Fri, Dec 13, 2013 at 11:42 AM, Colleen Whitney 
<[email protected]<mailto:[email protected]>> wrote:
I see two problems. The constraint definition is not in the search namespace 
(either add it to the root options node as the default namespace, or add the 
prefix to the constraint elements).

Right.  A leftover result of my poking around. :-)

Also, you have brackets inside the "". Try removing the brackets.


In this case I case see that they aren't needed.  However, they are in the 
examples.  In cases where I want to find ONLY an entire phrase, in an element.  
Wouldn't I use the brackets or single quotes to do grouping?


Debug tip: turn on the debug option using <search:debug>true<search:debug>, or 
use search:parse to see how your query is being parsed.


Great tip.  Thanks.

--Tim





Sent from my iPhone

On Dec 13, 2013, at 4:39 AM, "Timothy W. Cook" 
<[email protected]<mailto:[email protected]>> wrote:

In the BBQ tutorial: 
http://developer.marklogic.com/learn/2009-07-search-api-walkthrough

The examples using constraints are a bit confusing (for me) in the exact syntax.
For example, it doesn't explicitly say that the options need to be wrapped in 
<search:options>.

Anyway, the simple value example doesn't return any matches:

xquery version "1.0-ml";
import module namespace
  search = "http://marklogic.com/appservices/search";
  at "/MarkLogic/appservices/search/search.xqy";

search:search("[flavor:smoky]",
<search:options>
<constraint name="flavor">
  <value>
    <element ns="http://example.com"; name="flavor-descriptor"/>
  </value>
</constraint>
</search:options>)

Returns zero hits (with or without the brackets):

<?xml version="1.0" encoding="UTF-8"?>
<search:response snippet-format="snippet" total="0" start="1" page-length="10" 
xmlns:xs="http://www.w3.org/2001/XMLSchema"; xmlns="" 
xmlns:search="http://marklogic.com/appservices/search";>
  <search:qtext>[flavor:smoky]</search:qtext>
  <search:metrics>
    <search:query-resolution-time>PT0.006552S</search:query-resolution-time>
    <search:facet-resolution-time>PT0.000082S</search:facet-resolution-time>
    <search:snippet-resolution-time>PT0S</search:snippet-resolution-time>
    <search:total-time>PT0.006799S</search:total-time>
  </search:metrics>
</search:response>

There are three documents with "flavor-descriptor" = "smoky".

Thanks,
Tim



--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
_______________________________________________
General mailing list
[email protected]<mailto:[email protected]>
http://developer.marklogic.com/mailman/listinfo/general

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




--
MLHIM VIP Signup: http://goo.gl/22B0U
============================================
Timothy Cook, MSc           +55 21 94711995
MLHIM http://www.mlhim.org
Like Us on FB: https://www.facebook.com/mlhim2
Circle us on G+: http://goo.gl/44EV5
Google Scholar: http://goo.gl/MMZ1o
LinkedIn Profile:http://www.linkedin.com/in/timothywaynecook
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general

Reply via email to