Mike J
Mike J

Reputation: 159

MarkLogic: How to omit search facet values that are empty?

Using the default search endpoint and passing in an options file, I have a path range index set up on a particular element /path/to/my/element/.

I'm currently being returned the following in my facet:

<search:facet name="facetName" type="xs:string">
<search:facet-value name="" count="3"/>
<search:facet-value name="real value 1" count="1">real value 1</search:facet-value>
<search:facet-value name="real value 2" count="1">real value 2</search:facet-value>
</search:facet>

My desired output:

<search:facet name="facetName" type="xs:string">
<search:facet-value name="real value 1" count="1">real value 1</search:facet-value>
<search:facet-value name="real value 2" count="1">real value 2</search:facet-value>
</search:facet>

There's facet values being returned for empty elements, which I do not want. Is there a way to get rid of those empty facet values without having to write another transform to apply to the search results?

Upvotes: 0

Views: 163

Answers (2)

Sudeep Rawat
Sudeep Rawat

Reputation: 239

For desire output. You store generate output in variable and add condition as per mention below.

declare namespace search="http://www.search.com";

let $var1:=<search:facet name="facetName" type="xs:string">
              <search:facet-value name="" count="3"/>
              <search:facet-value name="real value 1" count="1">real value 1</search:facet-value>
              <search:facet-value name="real value 2" count="1">real value 2</search:facet-value>
            </search:facet>

return for $in in $var1
        return 
        <search:facet name="facetName" type="xs:string">{
        $in//search:facet-value[not(@name='')]}
        </search:facet>

Upvotes: 0

grtjn
grtjn

Reputation: 20414

The only sensible way would be to remove empty elements from your documents, if that is an option.

HTH!

Upvotes: 1

Related Questions