A client requested spelling suggestions to be returned from their GSA box, so I'm submitting a patch that implements that functionality. In 6.x.2.0-beta1, the spelling suggestion was being returned in the XML but was discarded if no results were returned.

Here, the spelling suggestion is pulled out and passed through PHP's exception handling to the theme layer, but only when no results are returned. There are changes to google_appliance.module and to GoogleMini.php. I have added configuration options for error messages when a spelling suggestion is returned. However, I haven't added any configuration option to turn the spelling suggestions on or off.

I hope others will find this feature useful and it can be integrated. We'd like to stay on the main branch if at all possible.

Thanks, David.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

neilang’s picture

FileSize
733 bytes

I wish I had seen this sooner. I recently ran into the same issue, and solved it in a similar manner.

I've attached my patch as an alternative.

EDIT: Ok, I just worked out that my patch doesn't fix spell suggestion, but hijack the synonym feature. Sorry!

neilang’s picture

FileSize
3.29 KB

I've made a new patch that implements spell suggestion without changing synonyms. It is a slight alternative to David's implementation, which might be useful to someone.

larskleiner’s picture

I don't seem to get spelling suggestions on my Google Mini, is this a GSA-only feature?

Sounds like a good idea to add support for it to this module though.

I tried neilang's patch from #2 and it looks good to me. I wasn't able to apply dbassendine's patch, I got the following error.

patch < google_appliance.module.spelling.patch
patching file google_appliance.module
Hunk #1 FAILED at 700.
Hunk #2 FAILED at 981.
Hunk #3 succeeded at 1134 (offset 27 lines).
Hunk #4 succeeded at 1155 (offset 27 lines).
Hunk #5 succeeded at 1501 (offset 51 lines).
2 out of 5 hunks FAILED -- saving rejects to file google_appliance.module.rej

jweowu’s picture

The current Mini (software v5) that I have access to provides spelling corrections.

We also wrote some awfully similar code to neilang's, which I'm attaching as a patch for the 6.x-2.x-dev branch.

It also contains a small number of other changes related to this sort of result "meta data":

  • A bug-fix for synonyms (see GoogleMini::resultfactory()) -- also spotted and fixed by neilang
  • Some error-prevention for google_appliance_cache_data()
  • Adds the result count value and the result_iterator object to the data passed to theme('google_appliance_search_view')

The last item isn't strictly relevant to this issue, but caching the result count was a useful addition for us (otherwise it's only available through the pager, but we weren't using that this time), and providing the iterator object makes good sense for enabling theme-level access to any present or future XML elements which aren't explicitly handled in the module.

One difference is how I've treated the suggestion output. neilang's patch makes it a link to a search for that word. I've intentionally not done this, because it's unclear to me that this is a useful thing to do. I haven't seen spelling corrections for anything other than single-word queries, but I've not noticed any documentation stating that this is the only circumstance in which they are generated, and I haven't done enough testing to feel positive about it either way. If spelling suggestions can be returned for words within a search phrase, than any 'suggestion' that links to a search for just one (corrected) word of that phrase is no use whatsoever (and the XML does not indicate the original mis-spelling, so search-and-replace isn't an option). As such, I've left the output as plain text.

I noticed the getChildValues() method in neilang's changes to GoogleMini.php, but I'm not sure that "q" attribute is a consistent format? I didn't want to abstract that out if it turned out to be a fairly arbitrary choice used for Spelling and Synonyms, but not used in other places.

For possible test purposes, if you don't have the feature available, the XML for spelling corrections looks like this:

<GSP VER="3.2">
  <TM>0.007412</TM>
  <Q>riverr</Q>

  [ PARAM LIST ...]

  <Spelling>
    <Suggestion q="river"><b><i>river</i></b></Suggestion>
  </Spelling>
</GSP>

edit:
p.s. I'm happy to rip out the result count value and result_iterator bits if you'd prefer, or simply to provide testing for neilang's version? (although I'd at least like to see "SpellingSuggestions" in the code instead of "SpellSuggestions" -- that's just not right :)