3
votes
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.

1

1 Answers

3
votes

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,