Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
521 views
in Technique[技术] by (71.8m points)

marklogic - Wildcarded search with "*" and "?" in search:search not working properly

We need to achieve the wildcarded searches with both the characters "*" and "?" as described in

https://docs.marklogic.com/10.0/guide/search-dev/wildcard

Wildcard Characters Marklogic Server supports two wildcard characters: * and ?.

  • matches zero or more non-space characters. ? matches exactly one non-space character. For example, he* will match any word starting with he, such as he, her, help, hello, helicopter, and so on. On the other hand, he? will only match three-letter words starting with he, such as hem, hen, and so on.

But we do the search as below,

let $options := <options xmlns="http://marklogic.com/appservices/search">   
                  <constraint name="DocumentTitle">
                    <word type="xs:string" facet="false">
                      <element ns="http://marklogic.com/nondeliverable" name="DocumentTitle"/>
                      <search:term-option>wildcarded</search:term-option>, 
                       <search:term-option>case-insensitive</search:term-option>,
                       <search:term-option>diacritic-insensitive</search:term-option>,
                       <search:term-option>unstemmed</search:term-option>
                    </word>
                  </constraint>
                  <return-query>true</return-query>
                  <return-qtext>true</return-qtext>
                  <return-metrics>true</return-metrics>
                </options>
                
return (search:search("(DocumentTitle:(medi*ation))",$options,1,10),search:search("(DocumentTitle:(medi?ation))",$options,1,10))

Both the search queries are returning same count. But if we do the search

cts:search(fn:doc(),cts:element-word-query(xs:QName("nd:DocumentTitle"),"medi?ation",("wildcarded"))),cts:search(fn:doc(),cts:element-word-query(xs:QName("nd:DocumentTitle"),"medi*ation",("wildcarded"))) 

the count are different and returning the proper result.

How we can achieve wildcarded searches with both the characters "*" and "?" in search:search with proper result.

question from:https://stackoverflow.com/questions/65919615/wildcarded-search-with-and-in-searchsearch-not-working-properly

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

cts:search runs filtered by default, while search:search runs unfiltered by default. Pass in filtered as option to cts:search, and see if that returns the same results as search:search.

Alternatively, you can also provide a search-option to make search:search behave filtered:

<search-option>filtered</search-option>

Filtering is slow by the way, and ideally you should choose index settings that make filtering unnecessary. Check if you have enabled wildcard settings.

HTH!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...