Problem/Motivation
I'm now using the latest stable version of search_api ( 7.x-1.12 ) on Drupal 7.28 and found that the result of searching with single CJK keyword ( like Japanese "ユーザ" ) doesn't show any excerpt while searching with English words works perfectly. My processors settings of search index are quite simple where the HTML filter and highlighting are enable. ( see the attached image )
Proposed resolution
In the constructor of SearchApiHighlight class declared in processor_highlight.inc, $split is defined like this.
self::$split = '/[' . PREG_CLASS_UNICODE_WORD_BOUNDARY . $cjk . ']+/iu';
Then, this variable is used to split search keywords in getKeywords function as follows:
protected function getKeywords(SearchApiQuery $query) {
$keys = $query->getKeys();
if (!$keys) {
return array();
}
if (is_array($keys)) {
return $this->flattenKeysArray($keys);
}
$keywords = preg_split(self::$split, $keys);
:
So, every time I use single CJK word in searching, preg_split used here returns empty array since $split covers all CJK ranges. I think $split should not cover and its definition should be as follows removing "$cjk" concatination
self::$split = '/[' . PREG_CLASS_UNICODE_WORD_BOUNDARY . ']+/iu';
So far, this fix works fine for me and if you need more information about my environment, kindly let me know.
| Comment | File | Size | Author |
|---|---|---|---|
| #2 | 2278791-2--cjk_highlighting.patch | 966 bytes | drunken monkey |
| Screen Shot 2014-06-03 at 12.40.19.png | 76.48 KB | tksmd |
Comments
Comment #1
tksmd commentedI slightly modified issue summary and title to make it a bit clearer this issue condition.
Comment #2
drunken monkeySince I don't really know anything about CJK handling, or why that code is there (it's different in Core Search, from where I copied most of the highlighting code), I can only trust your judgement there. The attached patch would implement this change, please test again. If no-one else objects, I'll commit this then.
In any case, thanks for reporting this and providing this analysis!
Comment #3
tksmd commentedI applied your patch and tested. That worked fine. Thanks!
Comment #4
tksmd commentedI've changed the status.
Comment #5
drunken monkeyOK, good to hear. Committed.
Thanks again!
Comment #8
drunken monkey(Ported to D8.)
Comment #10
drunken monkey