Hi Abhishek,
The problem is that MarkLogic does not resolve that query directly from the
indexes. That is why you have to do a filtered search in order to find that
this is not a match.
One way around this is to use an element-query constraint on your data element.
This would restrict the query to within the scope of that element. Here is an
example of that (including the underlying cts:query at the end of the example,
to help you understand how this works):
xquery version '1.0-ml';
xdmp:document-insert("/test.xml",
<test>
<data>hello</data>
<metadata>goodbye</metadata>
</test>);
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
let $options := <options xmlns="http://marklogic.com/appservices/search">
<searchable-expression>/test/data</searchable-expression>
<constraint name="data">
<element-query ns="" name="data" />
</constraint>
<search-option>unfiltered</search-option>
<debug>true</debug>
</options>
return
search:search("data:goodbye", $options, 1, 10);
xdmp:estimate(cts:search(doc("/test.xml")/test/data,
cts:element-query(xs:QName("data"), "goodbye")))
You will see that both queries find 0 matches, which is correct.
Hope that helps,
-Danny
From: [email protected]
[mailto:[email protected]] On Behalf Of Abhishek53 S
Sent: Wednesday, May 04, 2011 3:16 AM
To: General MarkLogic Developer Discussion
Subject: [MarkLogic Dev General] Problem with searchable-expression and
unfiltered search options
Hi All
Can I restrict my free text search to a part of the document?
Consider my document is of the following structure. I restrict my search to the
/test/data. I use search:search API and provide the XPATH in the
<searchable-expression> option. I am using unfiltered search for better
performance. Marklogic is returning if the free text is matches within metadata
tag also.
If I am using filtered search option the marklogic search is limited to the
data tag only. Please provide some suggestion to limit the search with
unfiltered search only.
Content
<test>
<data></data>
<metadata></metadata>
</test>
Query
let $options := <options xmlns="http://marklogic.com/appservices/search">
<searchable-expression>/test/data</searchable-expression>
<search-option>unfiltered</search-option>
</options>
return
search:search("free text", $options, 1, 10)
Thanks & Regards
Abhishek Srivastav
Assistant Systems Engineer
Tata Consultancy Services
Plot B-1, Block EP & GP, Sector 5
Salt Lake Electronics Complex,
Kolkata - 700 091,West Bengal
India
Cell:- +91-9883389968
Mailto: [email protected]
Website: http://www.tcs.com<http://www.tcs.com/>
____________________________________________
Experience certainty. IT Services
Business Solutions
Outsourcing
____________________________________________
=====-----=====-----=====
Notice: The information contained in this e-mail
message and/or attachments to it may contain
confidential or privileged information. If you are
not the intended recipient, any dissemination, use,
review, distribution, printing or copying of the
information contained in this e-mail message
and/or attachments to it are strictly prohibited. If
you have received this communication in error,
please notify us by reply e-mail or telephone and
immediately and permanently delete the message
and any attachments. Thank you
_______________________________________________
General mailing list
[email protected]
http://developer.marklogic.com/mailman/listinfo/general