Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
From BOF session at drupalcon
Comment | File | Size | Author |
---|---|---|---|
#8 | spellcheck.patch | 4.92 KB | robertDouglass |
#7 | spellcheck_patch_230380_2.txt | 4.85 KB | janusman |
#2 | spell_suggestion_patch.patch | 4.02 KB | janusman |
Comments
Comment #1
janusman CreditAttribution: janusman commentedDid some research and came up with the basic Solr configuration (no Drupal code yet!)
1) Install this patch to your solr installation's example/solr/conf/schema.xml
The field name is "word" because that's the way it's configured in solrconfig.xml--so DON'T CHANGE IT =)
2) Reindex... (remove example/solr/data, tell Drupal to reindex, restart solr, run cron.php a lot, etc.) =)
3) After some time, you need to rebuild the spelling dictionary. You do this calling Solr with a special URL (replace example.com with your hostname):
http://example.com:8983/solr/select?qt=spellchecker&cmd=rebuild
4) Now, you get suggestions for a query term like this:
http://example.com:8983/solr/select?qt=spellchecker&q=[word]
Sorry, it only accepts one word, so q=word1+word2 will not return any suggestions.
You can read a thread on this here: http://markmail.org/message/gluyo6mhuxqltzdh
Now... where should the actual PHP code for using suggestions go? The apachesolr.module... or SolrPhpClient?
Comment #2
janusman CreditAttribution: janusman commentedOk, got this working in an actual site (perhaps not very elegantly, or maybe not even correctly).
I patched apachesolr_search.module to return a "fake" $results[] element that includes the suggestion. To try it test out some queries on our test site:
Again, it only works with single words--no phrases. After patching the schema.xml, you need to copy it over to the Solr instance, reindex, etc etc as per the instructions in the previous comment.
Patch is for D5-1-alpha3.
Comment #3
janusman CreditAttribution: janusman commentedAnother small snippet to put at the end of apachesolr_search.module ... this one rebuilds the spellchecker automatically. Since it takes a while to do this (20-120 seconds) I set it up so it only does it every 24 hours.
Sorry, not yet pinging Solr beforehand...
Sorry for not issuing a complete patch... will work on it soon. =)
By the way I just went live with this on our production site... try it:
http://biblioteca.mty.itesm.mx/pasteur/en/search/apachesolr_search/testt
Comment #4
janusman CreditAttribution: janusman commentedJust a small FYI...
Spellchecker rebuild time benchmark for a Solaris 8 box.
2000 nodes: 20 seconds.
30,000 nodes: 65 seconds.
Comment #5
robertDouglass CreditAttribution: robertDouglass commentedGreat stuff. It's on my todo list.
Comment #6
robertDouglass CreditAttribution: robertDouglass commentedAre these issues duplicates? @janusman, can you please combine them and close one? http://drupal.org/node/303937
Plus I'm boosting this as critical = should be included in 1.0 release.
Comment #7
janusman CreditAttribution: janusman commentedI have a patch for the DRUPAL-5 branch. Will work on the D6 port.
This only works for single-word queries for now.
Comment #8
robertDouglass CreditAttribution: robertDouglass commentedTesting the patch, corrected a small error (need to use " instead of ' if variables are to evaluate). Now I'm getting the following:
http://localhost:8983/solr/select?qt=spellchecker&q=causi
HTTP ERROR: 400
unknown handler: spellchecker
RequestURI=/solr/select
I'm using the 1.3 nightly.
The word field is showing up in my index:
Apache Solr search index
Field name Field index type
changed integer
word spellText
In the attached patch I fixed the " bug, tweaked the message text, and replaced time() with $_SERVER['REQUEST_TIME'] (a suggestion from Rasmus Lerdorf in Szeged).
Comment #9
janusman CreditAttribution: janusman commentedSorry about the quotes.
I think the problem is that Solr1.3 differs from 1.2. Are we aiming to switch to Solr1.3 before the 1.0 release?
I will double check to see if the patch is correct (at least my code *is* spellchecking, and my Solr instance (1.2) is spellchecking). =)
Comment #10
janusman CreditAttribution: janusman commentedYup, 1.3 is different regarding spellcheck. See http://markmail.org/message/7tqnlgw6zums45p7 for a thread discussing this.
Comment #11
robertDouglass CreditAttribution: robertDouglass commentedOk. So we need to make a decision on this, before 1.0. I'm going to start another thread, but I think an OO approach to this is in order, complete with a factory that finds out which Solr we're running on somewhere along the line.
Comment #12
pwolanin CreditAttribution: pwolanin commentedWe have a basic version working in 6.x with 1.4 (and 1.3 before that).