问题
I used this expression to search documents
search:search(
'(content:"value of imports")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="content">
<element-query ns="" name="content" />
</constraint>
<additional-query>{cts:collection-query("document-binary")}</additional-query>
</options>
)
And had in result
<search:response snippet-format="snippet" total="16" start="1" page-length="10" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns="" xmlns:search="http://marklogic.com/appservices/search">
<search:qtext>(content:"value of imports")</search:qtext>
<search:metrics>
<search:query-resolution-time>PT0.319222S</search:query-resolution-time>
<search:facet-resolution-time>PT0.000124S</search:facet-resolution-time>
<search:snippet-resolution-time>PT0S</search:snippet-resolution-time>
<search:total-time>PT0.319721S</search:total-time>
</search:metrics>
</search:response>
The search will works correct if I leave only one word in the search expression
content:"value"
回答1:
The total
is an unfiltered estimate of the number of results. However the results are filtered by default. When the results do not match the count, you can try the unfiltered
option to see if that is the reason. You could also try using xdmp:query-trace
or the return-plan option for search:search
to see what is happening. You can also use cts:uris
to see the document URIs returned by the unfiltered search.
For more about filtered vs unfiltered search, see the docs at https://docs.marklogic.com/guide/search-dev/search-api and https://docs.marklogic.com/guide/search-dev/count_estimate and https://docs.marklogic.com/guide/performance/unfiltered
In this particular case the difference between filtered and unfiltered results might be due to the way the fast-phrase index works. Your phrase value of imports
will turn into a two word term value of
and a two word term of imports
. There may be 16 documents containing both of those terms. But that does not mean any of them match the entire three word phrase. If so the index lookup still matches 16, but filtering finds no matches.
回答2:
An element-query contraint matches a container of other elements:
- http://docs.marklogic.com/guide/rest-dev/appendixb#id_96729
If you want to match the textual content of an element, try a value or word query:
- http://docs.marklogic.com/guide/rest-dev/appendixb#id_21615
- http://docs.marklogic.com/guide/rest-dev/appendixb#id_18408
as in:
search:search(
'(content:"value of imports")',
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="content">
<value>
<element ns="" name="content" />
</value>
</constraint>
<additional-query>{cts:collection-query("document-binary")}</additional-query>
</options>)
If the document-binary collection tags binary documents, I would expect an empty result set because the additional query is and-related to other queries.
Hoping that helps,
Erik Hennum
来源:https://stackoverflow.com/questions/25722456/searchsearch-doesnt-return-any-snippets-but-searchresponse-total-is-bigge