Greetings,
We discovered a wrong behaviour of the search module indexing logic.
We created a web site which sells books. Book is a product content type and of course has title.
We have IT books about C++ and C#.
We found that it is impossible to find these books by "c++" or "c#". It doesn't work even if we enter "c++" in double quotes. In our situation it is very important because such keywords as "c++" or "c#" exists in titles and people would like to be able to find something when searching by "c++" or "c#".
The problem is that search module remove "+" and "#" characters when indexing content and when processing entered keywords. We would like to propose you a patch which fixes this issue. We remove these characters ONLY when they are encountered in the end of the word but not in the middle.
At the moment we do this for "+" and "#" characters only but we hope you can improve this patch and make it more general.
| Comment | File | Size | Author |
|---|---|---|---|
| search.patch | 1.13 KB | taldy |
Comments
Comment #1
drummChanges in behavior like this need to happen in the development version and then backported to stable versions as needed. The patch does not apply cleanly to CVS HEAD.
Comment #2
jhodgdonThis still needs to be fixed.
Comment #3
jhodgdonComment #4
jhodgdonComment #5
jhodgdonComment #6
jhodgdonSo.. This issue has been open for more than 5 years.
The problem is that the Search module treats all punctuation, including + and # characters, as word boundaries, so when indexing content, it replaces them by a space. The patch that was added to this issue, just after that replacement, attempted to find + and # characters specifically, in the middle of a word, and remove them. So two problems:
- Those characters have already been removedin the line before.
- Even if this patch line was moved up in the function, it would have only worked for things like "hello+hi", indexing them like "hellohi", but it would not help with either c++ or c# since the punctuation characters are at the end of the word.
- Furthermore, in the case of c# it is only two characters long, and at least by default, search indexing excludes words less than 3 characters long.
I do not see how we could really fix this using logic.. What I would suggest for anyone who wants to index specific terms like c++ and c# that they implement hook_search_preprocess(), and change "c++" to "cplusplus" and "c#" to "csharp" for purposes of search indexing and searching. This happens before the punctuation removal, and would be the right way to resolve this issue.
Note that this hook still exists in Drupal 8. There's an issue to change preprocessing into a plugin system, but it has not happened yet and may never happen: #257007: Convert hook_search_preprocess() into a plugin
So... after all this time, I'm just going to change this to a support request and mark it as "fixed", since a solution has been proposed.