Reputation: 65
How do I transform the results in search using the rest API; specifically the snippet part?
I'm currently looking at this document but I can't understand where to put it since there are so many ways to add such a thing.
I'm trying to get the whole document put into the snippet part.
<transform-results apply="snippet">
<per-match-tokens>30</per-match-tokens>
<max-matches>4</max-matches>
<max-snippet-chars>200</max-snippet-chars>
<preferred-matches/>
</transform-results>
It would be helpful if there were some kind of examples.
Upvotes: 3
Views: 256
Reputation: 20414
Here a pretty common example of default snippeting, as well as a few results states for different snippeting:
<options xmlns="http://marklogic.com/appservices/search">
<!-- The default snippeting behavior, average size snippets, if no results state was specified -->
<transform-results apply="snippet">
<preferred-elements>
<element ns="" name="body"/>
</preferred-elements>
<max-matches>2</max-matches>
<max-snippet-chars>200</max-snippet-chars>
<per-match-tokens>20</per-match-tokens>
</transform-results>
<!-- Pass in operator-state or use results: to select one of these states -->
<operator name="results">
<!-- results:compact, returns smallest snippets -->
<state name="compact">
<transform-results apply="snippet">
<preferred-elements>
<element ns="" name="body"/>
</preferred-elements>
<max-matches>1</max-matches>
<max-snippet-chars>100</max-snippet-chars>
<per-match-tokens>10</per-match-tokens>
</transform-results>
</state>
<!-- results:detailed, returns largest snippets -->
<state name="detailed">
<transform-results apply="snippet">
<preferred-elements>
<element ns="" name="body"/>
</preferred-elements>
<max-matches>3</max-matches>
<max-snippet-chars>300</max-snippet-chars>
<per-match-tokens>30</per-match-tokens>
</transform-results>
</state>
<!-- results:raw, returns full documents -->
<state name="raw">
<transform-results apply="raw"/>
</state>
</operator>
</options>
You can easily blend in operator state selection in your search string, just add something like results:detailed
. You can also use operator-state
in structured queries.
HTH!
Upvotes: 7