Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

MarkLogic Search With Constraint Returning Wrong Result

xquery version "1.0-ml";

import module namespace
  search = "http://marklogic.com/appservices/search"
  at "/MarkLogic/appservices/search/search.xqy";

let $options := 
  <options xmlns="http://marklogic.com/appservices/search">
    <constraint name="city">
      <value>
        <element  name="city"/>
      </value>
    </constraint>
    <sort-order type="xs:string" collation="http://marklogic.com/collation/"
      direction="ascending">
      <element ns="" name="userName"/>
    </sort-order>
  </options>
return search:search("city : Atlanta", $options)

when i am executing above query on qconsole with city : Atlanta i am getting correct matched documents details (ie 2 match) but when i am doing city NE Atlanta using above query i am getting wrong result...it means getting all the Documents Available in ML.

My Requirement is when is when i pass city NE Atlanta it should show zero match instead of showing all documents from ML.

Also i don't want to create Range index for city, because this field may changes at runtime.

Please Correct me if i am wrong.

like image 266
DevNinja Avatar asked Apr 08 '26 11:04

DevNinja


1 Answers

In document searches, comparisons are only available for range queries.

The Search API ignores invalid queries, yielding an empty query, which matches all documents in the database.

Negation queries, however, are available on value queries by prefixing the constraint with a minus (as in "-city:Atlanta"), yielding:

<cts:not-query xmlns:cts="http://marklogic.com/cts">
  <cts:element-value-query>
    <cts:element>city</cts:element>
    <cts:text xml:lang="en">Atlanta</cts:text>
  </cts:element-value-query>
</cts:not-query>

Does that query retrieve the documents you expect?

Hoping that helps,

like image 189
ehennum Avatar answered Apr 11 '26 02:04

ehennum



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!