Using the search API, I would like to find a way that allows the end user to specify a search criteria that would enable them to extend the search to include additional documents. I thought that maybe this could be done by providing an operator with an <additional-query> to reach out and gather more documents into the search. The sample code below shows that a "regular" search will look in the "/main/" directory. If the user types in "filter:type1", I would expect the search to also include documents found in the "/main/type1/" directory. Likewise if the user searches "filter:type2", I would expect the documents inside of "/main/type2/" directory to also be included. I couldn't find any examples of <additional-query> usage, so perhaps I've done it incorrectly. The documentation does seem to suggest that the additional query will be "and-ed" to the original query.
What I'm seeing is that "filter:type1" is recognized as an operator, but the <additional-query> is not being applied. Am I missing something? Is there a better way to solve this problem? Thanks David This is running on 4.1-1 with Windows 7 Sample code xquery version "1.0-ml"; import module namespace search = "http://marklogic.com/appservices/search" at "/MarkLogic/appservices/search/search.xqy"; let $insert := xdmp:document-insert("/main/a.xml", <a/>) let $insert := xdmp:document-insert("/main/b.xml", <b/>) let $insert := xdmp:document-insert("/main/type1/c.xml", <c/>) let $insert := xdmp:document-insert("/main/type1/d.xml", <d/>) let $insert := xdmp:document-insert("/main/type2/e.xml", <e/>) let $insert := xdmp:document-insert("/main/type2/f.xml", <f/>) let $searchOptions := <options xmlns="http://marklogic.com/appservices/search"> <operator name="filter"> <state name="type1"> <additional-query> xdmp:directory("/main/type1/", "1") </additional-query> </state> <state name="type2"> <additional-query> xdmp:directory("/main/type2/", "1") </additional-query> <debug>true</debug> </state> </operator> <searchable-expression> xdmp:directory("/main/", "1") </searchable-expression> <debug>true</debug> </options> return (search:parse("filter:type2", $searchOptions), search:search("filter:type2", $searchOptions)) Results <v:results v:warning="more than one node"> <cts:and-query qtextempty="1"> <cts:annotation operator-ref="filter" state-ref="type2" qtextconst="filter:type2"/> </cts:and-query> <search:response total="2" start="1" page-length="10"> <search:result index="1" uri="/main/a.xml" path="doc("/main/a.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/main/a.xml")/a"/> </search:snippet> </search:result> <search:result index="2" uri="/main/b.xml" path="doc("/main/b.xml")" score="0" confidence="0" fitness="0"> <search:snippet> <search:match path="doc("/main/b.xml")/b"/> </search:snippet> </search:result> <search:qtext>filter:type2</search:qtext> <search:report id="SEARCH-FLWOR"> (for $result in cts:search(xdmp:directory("/main/", "1"), cts:and-query((), ()), ("score-logtfidf"), 1) order by cts:score($result) descending return $result)[1 to 10] </search:report> <search:metrics> <search:query-resolution-time>PT0.055S</search:query-resolution-time> <search:facet-resolution-time>PT0S</search:facet-resolution-time> <search:snippet-resolution-time>PT0.002S</search:snippet-resolution-time> <search:total-time>PT0.057S</search:total-time> </search:metrics> </search:response> </v:results> NOTICE: This email message is for the sole use of the intended recipient(s) and may contain confidential and privileged information. Any unauthorized review, use, disclosure or distribution is prohibited. If you are not the intended recipient, please contact the sender by reply email and destroy all copies of the original message.
_______________________________________________ General mailing list [email protected] http://xqzone.com/mailman/listinfo/general
