I have been asked by a client to reduce the amount of false positives that Apache Solr was providing in the 'Did you mean?'. Some words in the index were perfectly valid, but Solr insisted on trying to suggest more popular terms.
E.g. a search for 'woods' (in 11 documents) would return 'did you mean? foods' (in 69 documents)
This feature patch aims to provide the ability to ask Solr for:
$params['spellcheck.extendedResults'] = 'true';
These extended spell check results include the frequency to which the word appears in the index, and also whether or not Solr thinks the word is spelled correctly.
I made a new addition to the Solr configuration page to include:
- A checkbox to show only if the word is misspelled
- A textfield to set the minimum original frequency to suppress the 'did you mean?'
This way an admin can easily suppress the 'did you mean?' to words that appear in fewer than 5 documents for instance, or alternatively only show for misspelled words (appear in 0 documents in the index).
What are your thoughts on this patch, is it likely this can be accepted upstream into the module?
Thanks
Sean
| Comment | File | Size | Author |
|---|---|---|---|
| #34 | 1361854-apachesolr-suggestions-alter-11.patch | 1.83 KB | acbramley |
| #22 | 1361854-10.patch | 1.77 KB | acbramley |
| #18 | allow-suggestion-objects.patch | 706 bytes | acbramley |
| #9 | 1361854-9.patch | 1.01 KB | nick_vh |
| #8 | 1361854-8.patch | 1.04 KB | nick_vh |
Comments
Comment #1
nick_vhVery interesting of course.
Can this be commented? Can we prevent this?
This is also not wanted, since we do allow searches from more then 1 environment
I'll try to test it out now :-)
Comment #2
nick_vhRerolled the patch so it applies on the latest dev version.
There is however still one problem it seems. The following code did not validate on my system.
I only got
Maybe there is a difference between Solr 1.4 and 3.x?
Comment #3
wiifmHi Nick_vh,
Yes, I forgot to mention that we are running on Solr version 3.1.0, and I don't really have access to Solr 1.4 to test this with.
This is the raw Solr response from the query
http://127.0.0.1:8983/solr/[core-name]/select/?q=Cancer%20trends&spellcheck=true&spellcheck.build=true&version=2.2&spellcheck.extendedResults=trueMy response above seems to marry up with the documentation at http://wiki.apache.org/solr/SpellCheckComponent#Extended_Results where it says:
Can you post the last part of your response from Solr?
S
Comment #4
acbramley commentedThe line if ($min_freq >= $value->suggestion[0]->origFreq) had the incorrect logic. Altered the patch in #2 to use correct logic.
Comment #5
nick_vhOk, I gave it another try with my standard test and it was not giving me the same result. We should have a way to enable or disable the advanced spelchecker so the original behavior does not get lost.
Comment #6
nick_vhI'm a bit doubtful for the final implementation for this. It seems that the purpose is very specific and the UI to configure it will not be very clear for most of the people?
Are you able to do this without hacking the module? In other words, by using the hooks provided? You could easily make a new contrib module that extends this module and if I was you I would go for that solution?.
Comment #7
wiifmHi @Nick_vh,
Is there a hook that can alter the spell checker results before they are returned? The only reason why I patched the module was because I saw no other way to achieve this
Comment #8
nick_vhWould this be sufficient?
Comment #9
nick_vhAnd now with a newline
Comment #10
nick_vhComment #11
wiifmYes - that would be perfect, and would mean I can place my customisations into our modules and leave apachesolr clean ;)
Will apply the patch at work, and make sure it is all good
Comment #12
acbramley commented@Nick_vh this hook doesn't allow us to add $params['spellcheck.extendedResults'] = 'true'; which is needed to get those extra parameters.
Comment #13
nick_vhhook_query_alter? That should be sufficient to add that parameter?
Comment #14
nick_vhComment #15
acbramley commentedAh yes, that does work :)
Comment #16
nick_vhComment #17
acbramley commentedHowever, adding this parameter changes the structure of the suggestions array, making (apahcesolr_search.module +856):
incorrect as the word is now under $value->suggestion[0]->word. Any ideas of how to get around this?
Comment #18
acbramley commentedThis patch fixes the above problem for both cases.
Comment #19
nick_vhWithout documentation this patch is as fuzzy as a patch could be? Would there really not be any other way?
Comment #20
acbramley commentedNope, because when you add the query parameter to return extended results it changes the suggestions from an array of strings to an array of objects.
Comment #21
acbramley commentedLooking at the drupal_alter call on the suggestions as well, this doesn't provide what we need as that will only pass in the string that it will suggest. This means that none of the properties (origFreq etc) are available in the alter hook. It would be much better to do it like this:
Comment #22
acbramley commentedSorry, wrong again. This patch includes the correct placing and variables to use in the alter hook so we have something useful, and the change in the foreach loop with documentation as to what it's for :)
Comment #23
nick_vhI don't like this approach. It would be better if you actually remake the array so it fits in to the function properly.
Comment #24
halcyonCorsair commented@Nick_vh:
Could you please exand on that comment? We're flying in the dark here about what you want, and why you're rejecting our suggestions.
Comment #25
nick_vhsorry if I sounded rude :-)
I would prefer that the logic of this $value->suggestion[0]->word happens in the alter.
We are adding query specific syntaxes here and that is not necessary.
I'd prefer if we reworked it to something similar like :
This way we do everything in the alter and we can add more suggestion query weirdness if one would want?
Comment #26
milesw commentedI think you can address some of these problems through changes to Solr config.
Regarding the original issue:
Try settings spellcheck.onlyMorePopular to "false". Solr keeps it off by default, but the config for apachesolr.module turns it on. It's a misleading option, which sounds helpful, but I find it leads to worse suggestions overall.
And regarding the other part:
Another possibility is to use a spellchecker config option called "thresholdTokenFrequency". Seems to be undocumented, but here is a stack overflow example). This tells the spellcheck component to ignore terms found in less than a certain percentage of documents.
Comment #27
petednz commentedThis thread looks like it ran out of steam - did it get picked up somewhere else. In the meantime - can someone clarify if the suggestion to "Try settings spellcheck.onlyMorePopular to "false"" is a UI setting or actually in the module? I am assuming the latter but happy to get a nice surprise (though I can't find it)
Comment #28
milesw commented@petednz: It's a Solr parameter that can be set in solrconfig.xml or overridden with URL parameters. The solrconfig.xml bundled with apachesolr.module sets it to true. You can use hook_apachesolr_query_alter() or hook_apachesolr_query_prepare() to override that setting.
Comment #29
petednz commentedsweet. really appreciate your prompt and useful response.
Comment #30
daniel.nitsche commented@milesw, I'm assuming you're running Solr 1.4? That feature doesn't seem to be available in Solr 3, or at least it's never worked for me.
Comment #31
milesw commented@daniel.nitsche: I was using 3.x. Are you referring to the onlyMorePopular feature? If you changed it in solrconfig.xml don't forget you have to reload the config. :)
The only change I'm aware of is in Solr 4.x where you can optionally use the DirectSolrSpellChecker instead of the default IndexBasedSpellChecker. As I understand it, the onlyMorePopular param irrelevant with that new spell checker.
Comment #32
acbramley commentedI completely lost track of this issue as I moved off the project that was using the patch. While there's valid suggestions as to what other things you can do with solrconfig and parameters to achieve similar functionality, an alter hook gives you far more power and flexibility. We've been using this extensively since the patch #22 was posted. This is the example of how we use it:
Setting to needs review to try kick this off again
Comment #34
acbramley commentedWoops, needed a reroll.
Comment #35
nick_vhI'll give in and commit this. But we should actually get a cleaner solution but let's take this as part of the solution. Committed to 7.x-1.x and needs backport now
Comment #36
acbramley commentedThanks @Nick_vh, feel free to add a comment above the line you are not happy with as a TODO to fix :)