Reputation: 1369
I spend most of the afternoon trying to add a facet to an example application based on the marklogic slush template.
It has a facet on eyeColor based on an element range index.
sample data can be found here
My goal is to add a facet on gender , which is also an element in the example json data. So I added an element range index on localname gender. Same collation endpoint.
Then I Reindexed
Now I try to understand if I need additional changes in the front end application before the facet turns up in the application.
From the backend I try to understand how I can see which facets (or contraints) are available on my search call using an example xquery on the console. Seems I cannot find the right search:search function to retrieve the facet information from the console, not even the existing one on eyeColor.
If I know what I want I can pass a constrained in the options parameter, but is seems the front-end is not aware of the specific facets the search-api returns or am I wrong?
On the console I tried:
xquery version "1.0-ml";
import module namespace search = "http://marklogic.com/appservices/search"
at "/MarkLogic/appservices/search/search.xqy";
search:search(" ",
<options xmlns="http://marklogic.com/appservices/search">
<return-results>true</return-results>
<return-facets>true</return-facets>
<constraint name="eyeColor">
<range collation="http://marklogic.com/collation/codepoint/" type="xs:string">
</range>
</constraint>
</options>)
But that does not contain facet results...
Yes I read most of existing questions on ML facets here at SO but no luck still...
Can anyone set me on the right track here?
hugo
Upvotes: 1
Views: 164
Reputation: 1369
ok I got it... you have to add the option to the rest api options in the folder app-root/rest-api/config/options/all.xml
add an option (gender) like
<search:constraint name="gender">
<search:range type="xs:string" facet="true" collation="http://marklogic.com/collation/codepoint">
<search:facet-option>limit=5</search:facet-option>
<search:facet-option>frequency-order</search:facet-option>
<search:facet-option>descending</search:facet-option>
<search:json-property>gender</search:json-property>
</search:range>
</search:constraint>
deploy again using roxy, rmeber you also need a range index...
Upvotes: 1