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.

Comments

tksmd’s picture

Title: Exceprt won't shown when searching CJK words only » Excerpt won't be shown when searching single CJK word alone
Issue summary: View changes

I slightly modified issue summary and title to make it a bit clearer this issue condition.

drunken monkey’s picture

Version: 7.x-1.12 » 7.x-1.x-dev
Component: Framework » Plugins
Status: Active » Needs review
StatusFileSize
new966 bytes

Since 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!

tksmd’s picture

I applied your patch and tested. That worked fine. Thanks!

tksmd’s picture

Status: Needs review » Reviewed & tested by the community

I've changed the status.

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

OK, good to hear. Committed.
Thanks again!

  • drunken monkey committed 883af65 on 7.x-1.x
    Issue #2278791 by drunken monkey | tksmd: Fixed excerpt when searching...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

drunken monkey’s picture

Version: 7.x-1.x-dev » 8.x-1.x-dev
Status: Closed (fixed) » Patch (to be ported)

(Ported to D8.)

  • drunken monkey committed 4611ce1 on 8.x-1.x
    Issue #2278791 by drunken monkey | tksmd: Fixed excerpt when searching...
drunken monkey’s picture

Status: Patch (to be ported) » Fixed

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.