Retrieving spelling corrections and DYM in query results

You can retrieve automatic spelling corrections and suggested corrections (Did You Mean) information in a query using the SearchAdjustmentConfig type in your Conversation Web Service request.

If spelling is enabled in the data domain and you want the Conversation Web Service response to contain supplemental information about spelling corrections and spelling suggestions (DYM), a SearchAdjustmentConfig type is required. If it is included, spelling corrections and/or DYM suggestions are returned as part of the response.

It is important to realize that if spelling is enabled, spelling auto-correction occurs even if the SearchAdjustmentConfig type is not included. However, while spelling correction takes place, the spelling corrections and DYM suggestions are not returned in the response.

SearchAdjustmentConfig syntax

The format for a SearchAdjustmentConfig is:
<SearchAdjustmentConfig Id="?">
   <StateName>?</StateName>
</SearchAdjustmentConfig>
where the attributes mean:
Attribute Meaning
Id A required attribute that provides an arbitrary identifier for this configuration.
StateName Specifies an existing named state in the request, using these rules:
  • If the request has multiple named states, then the StateName element must reference one (and only one) of the named states.
  • If the request has only one named state, then it is optional as to whether the StateName element is used to reference that named state (as the state will be used in any event in the RecordListConfig).
  • If the request has an unnamed state, then the StateName element cannot be used.

SearchAdjustmentConfig example

This record search example includes the SearchAdjustmentConfig type, to ensure that spelling correction adjustments and DYM suggestions are returned in the response:
<Request xmlns="http://www.endeca.com/MDEX/conversation/3/0">
   <State>
      <TextSearchFilter Key="Flavors" Mode="AllPartial" EnableSnippeting="false" Language="en">pech</TextSearchFilter>
   </State>
   <RecordListConfig Id="RecList" MaxPages="10">
      <Column>Flavors</Column>
      <RecordsPerPage>5</RecordsPerPage>
   </RecordListConfig>
   <SearchAdjustmentConfig Id="SpellCorrect"/>
</Request>

Note that in the example, the word "peach" is misspelled as "pech".

Automatic spelling correction response

The response from the Conversation Web Service contains the original State from the request with search filter applied, as well as the original (not yet spelling-corrected) term of "pech". The response also includes the SearchAdjustments type:
<cs:SearchAdjustments Id="SpellCorrect">
   <cs:AppliedAdjustment>
       <cs:TextSearchFilter Key="Flavors" Mode="AllPartial">pech</cs:TextSearchFilter>
       <cs:AdjustedTerms>peach</cs:AdjustedTerms>
   </cs:AppliedAdjustment>
</cs:SearchAdjustments>

The SearchAdjustments response includes the automatically-corrected term "peach" in the AdjustedTerms element for AppliedAdjustment. The name of the element ("AppliedAdjustment") tells you that the corrected spelling was automatically applied to the query, and the results (2593 records in this example) reflect that correction.

Explicit spelling suggestions (DYM) response

For explicit spelling suggestions, the SearchAdjustments response contains a SuggestedAdjustment element (instead of an AppliedAdjustment element), as in this example from a search that used the misspelling of "pechr" instead of "peach":
<cs:SearchAdjustments Id="SpellCorrect">
   <cs:SuggestedAdjustment RecordCountIfApplied="2593">
       <cs:TextSearchFilter Key="Flavors" Mode="AllPartial">pechr</cs:TextSearchFilter>
       <cs:SuggestedTerms>peach</cs:SuggestedTerms>
   </cs:SuggestedAdjustment>
</cs:SearchAdjustments>

The name of the element ("SuggestedAdjustment") tells you that the term is just a DYM suggestion, which means that it was not applied to the query. The RecordCountIfApplied element shows that if the suggestion had been applied, 2593 records would have been returned. To retrieve those records, re-send the record search query with the suggested term of "peach" for the search term.