Reputation: 1179
Sorry for a long question, not sure how to explain my issue other than this..
I have a query
let $q := '(*) AND ((context:"KN"))'
my options
let $options :=
<options xmlns="http://marklogic.com/appservices/search">
<constraint name="context">
<range type="xs:string" facet="true">
<element name="context" ns="http://ir.abbvienet.com/content-repo/metadata"/>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
</range>
</constraint>
<constraint name="gene">
<range type="xs:string" facet="true">
<path-index>//Hit[@type='GENE']/@id</path-index>
<facet-option>frequency-order</facet-option>
<facet-option>descending</facet-option>
<facet-option>limit=10</facet-option>
</range>
</constraint>
<return-results>false</return-results>
<return-facets>true</return-facets>
<term>
<term-option>case-insensitive</term-option>
<term-option>punctuation-insensitive</term-option>
<term-option>whitespace-insensitive</term-option>
<term-option>wildcarded</term-option>
</term>
<search-option>unfiltered</search-option>
</options>
When I do search:search($q, $options)
I get the following result
<search:facet name="gene" type="xs:string">
<search:facet-value name="DMPK" count="846">DMPK</search:facet-value>
<search:facet-value name="TNF" count="323">TNF</search:facet-value>
<search:facet-value name="IL6" count="301">IL6</search:facet-value>
<search:facet-value name="PAGE4" count="297">PAGE4</search:facet-value>
<search:facet-value name="INS" count="296">INS</search:facet-value>
<search:facet-value name="PSD" count="291">PSD</search:facet-value>
<search:facet-value name="EGFR" count="280">EGFR</search:facet-value>
<search:facet-value name="PAGE3" count="271">PAGE3</search:facet-value>
<search:facet-value name="PAGE5" count="270">PAGE5</search:facet-value>
<search:facet-value name="CD4" count="268">CD4</search:facet-value>
</search:facet>
<search:qtext>(*) AND ((context:"KN"))</search:qtext>
Which is right,, Now I wanted to use search:values
to get the faceting of gene
.. And I do the following
let $valueOptions :=
<options xmlns="http://marklogic.com/appservices/search">
<values name="facet">
<range type="xs:string" facet="true">
<path-index>//Hit[@type='GENE']/@id</path-index>
</range>
<values-option>frequency-order</values-option>
<values-option>descending</values-option>
</values>
</options>
return search:values('facet', $valueOptions, search:parse($q, $options, 'search:query'),(), (), 1, 10)
I get the following results
<search:values-response name="facet" type="xs:string" xmlns:xs="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:search="http://marklogic.com/appservices/search">
<search:distinct-value frequency="12528">EGFR</search:distinct-value>
<search:distinct-value frequency="8305">ERBB2</search:distinct-value>
<search:distinct-value frequency="7997">CD274</search:distinct-value>
<search:distinct-value frequency="7771">PDCD1</search:distinct-value>
<search:distinct-value frequency="7410">ALB</search:distinct-value>
<search:distinct-value frequency="6910">CTLA4</search:distinct-value>
<search:distinct-value frequency="6849">PARP1</search:distinct-value>
<search:distinct-value frequency="6740">MET</search:distinct-value>
<search:distinct-value frequency="6243">BTK</search:distinct-value>
<search:distinct-value frequency="6234">TNF</search:distinct-value>
<metrics xmlns="http://marklogic.com/appservices/search">
<values-resolution-time>PT0.021358S</values-resolution-time>
<total-time>PT0.022609S</total-time>
</metrics>
</search:values-response>
What I noticed is that the search:values
is ignoring the constraint in my search string, or it is not using the output of search:parse
the right way..
Why is the output not coming the same ? Am I missing something
Upvotes: 1
Views: 37
Reputation: 20414
I assume you feed search:values
with the same $q
as search:search
, but you are passing in $valueOptions
which doesn't have the constraint definition for context
.
Add the values
definition to $options
, and use that for search:values
.
HTH!
Upvotes: 2