简体   繁体   中英

Marklogic Xquery search:search term-option

Below query gives me wrong result count:

<options xmlns="http://marklogic.com/appservices/search">     
  <constraint name="Keyword">
    <range type="xs:string" 
           facet="true" 
           collation="http://marklogic.com/collation/">
      <element ns="" name="keyword"/>
      <facet-option>frequency-order</facet-option>
      <facet-option>descending</facet-option>
      <facet-option>limit=1</facet-option>
    </range>
  </constraint>
</options>;
let $query-text  := "pankaj!"
let $response := search:search($query-text, $query-options1)
return $response

there is no word "pankaj!" in my ML DB, but it gives 33 response. 33 is true for word "pankaj" but not for "pankaj!". "!" is getting removed from the query text.

<search:response snippet-format="snippet" 
  total="33" 
  start="1" 
  page-length="10" 
  xmlns:xs="http://www.w3.org/2001/XMLSchema" 
  xmlns="" 
  xmlns:search="http://marklogic.com/appservices/search"> 

Please let me know how to set term-option to get correct result.

Thanks.

Both wst and mblakele have usefull remarks, but there is still one more issue with your code. You declare a facet, which you can use for fielded search. But you are not using it. You need to prepend "Keyword:" in front of your search term.

If you don't the search term is treated as a word query, and that will cause punctuation to be removed as mblakele explains. Using the prefix should improve the count, if your search term occurs outside keyword elements as well. To get what you really want, the hints from wst and Will to add punctuation-sensitive are probably valuable too..

HTH!

Word indexes are not punctuation-sensitive, because words are not punctuation. I recommend reading http://developer.marklogic.com/try/ninja/page8 to understand the various query options and http://docs.marklogic.com/guide/search-dev/count_estimate to understand index lookups.

Adding punctuation automatically makes that term punctuation-sensitive: http://docs.marklogic.com/cts:word-query explains this. But the search total will still show the punctuation-insensitive estimate, because the indexes are punctuation-insensitive.

This will force a match on the exclamation (or any punctuation):

<term>
  <term-option>punctuation-sensitive</term-option>
</term>

I would also recommend using a punctuation-sensitive collation ( http://marklogic.com/collation//S4 ) in your configuration for the range index used for that constraint.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM