Current stemming modules transform words in the input file to their stem using preprocessing (hook search_preprocess). As a result all entries in word.search_index and the complete text in data.search_dataset is transformed to the stem equivalents.
When preparing the snippet to be shown in search results, search_files uses the code
'snippet' => search_excerpt($keywords, $dataset->data),
what results in a sequence of stemmed word shown to the user.
In the opposite module "node" avoids this by handing over the original (unstemmed) text
'snippet' => search_excerpt($keys, $node->body),
Comments
Comment #1
schildi commentedPlease check if the following changes can be applied to your module:
after line
search_index($file->id, 'search_files', $file_text);append the following two lines:
exchange
'snippet' => search_excerpt($keywords, $dataset->data),by
'snippet' => search_excerpt($keywords, $result->body),Comment #2
jrglasgow commentednow that you have brought this to my attention I agree that it needs to be fixed. if you would create a patch it would be most useful, otherwise it will take me more time to get this change made.
Comment #3
schildi commentedPlease check the appended patch
Comment #4
schildi commentedStatus changed: see #3
Comment #5
ezraw commentedI couldn't get this patch to work as expected. I applied it against 1.6 and the snippet disappeared (which is admittedly better than the trimmed words). I expected it to show the full snippet but without the trimmed stem. I uninstalled, reinstalled and did not get any results from search files at all, but probably not related the patch? Not sure, and since there is a 2.0 dev version I decided to try that.
This problem exists in the 2.0 beta4 version as well. With stemming the words are trimmed to their stems.
Since this issue is pretty old and it looks like the 2.0 version is the way to go now, I am going to update this issue and set it to the new version and make the status active. Hope that's OK.
Comment #6
schildi commentedHello Ezra
I'm not sure to understand what you did. The "snippet patch" accompanies the german stemmer. My site is still running D5, but I expect it to run seamlessly on D6 either.
But when you are using a different stemmer (e.g. the english porter stemmer) it will not work out of the box. The german version "de_stemmer" provides a function "de_stemmer_stem_list" which returns some kind of a lookup table. This function is probably not provided by other stemmers (but should be quite easily implemented).
But you are talking about "search files". As you can see in the patch I provides there was some issue with this module (5.x version):
* When using a stemmer the original text is/was overwritten with the stemmed version.
* Therefore the database table should be altered to keep the original text
* And one or two source lines should be altered too to use the new column
* If a file is attached to a node the corresponding node permissions should be checked
* and in the case the file is attached to a node it would be nice to have a link pointing to this node
And please don't forget to re-index your site!
Does this help?
To have a look at possible results, please check e.g.
http://archiv.bgv-rhein-berg.de/de/search/search_files/häuser
"Häuser" is the german plural form of "Haus". You can see that singular and plural forms are highlighted.
Regards
Comment #7
ezraw commentedAh, OK. That makes more sense now. I was using the English porter stemmer. I wasn't actually using this module on a site but just taking some time to review patches (patch bingo). This one popped up and the functionality seems useful so I thought I'd give it a try.
I'd review it against German but ich spreche kein Deutsch!
Comment #8
schildi commentedwhen just applying the patch I provided for "search files", then the original text will be kept correctly in a new column "body". But when searching the stemmed word will be looked at in the original text and probably now found. Therefore I provided a lookup function (included in de_stemmer, patch against search.module) which will map the stemmed words to their corresponding words in the text.
Comment #9
henkiejan commentedHello,
The problem with a snippet of stemmed words also exists for search attachments. The patch doesn't work there; there's no table for attachments to save the original text. Is it necessary to create a new table for attachments and changing the code in the same way as for files?
A new table and a lot of code, just for a correct search-snippet, or is there another way?
Erik Greve
www.kennisakker.nl
Comment #10
schildi commentedAs far as I know "search files" and "search attachments" both rely on the core search functionality. And this does not contain functions to handle a stemmed text.
Comment #11
henkiejan commentedOk then, for search attachments I've added an extra table:
Then a few extra lines in this function:
And last but not least, added/changed two lines in the hook_search-function:
$text = db_result(db_query("SELECT content FROM {search_files_attachments} WHERE id = %d", $item->sid));'snippet' => search_excerpt($keywords, $text),
That did the trick!
Erik Greve
(sorry, I can't make patches)