Can I search without distinguishing full-width/half-width characters or hiragana/katakana?
Kuroco's content search functions (topics_keyword, full_text_search, and Filter search) have no setting to treat full-width/half-width characters or hiragana/katakana as the same.
To search this way, use full_text_search and convert the following two strings to the same format with mb_convert_kana.
- The search string registered with the keyword template
- The search keyword sent in the API request
With full_text_search, uppercase and lowercase letters are not distinguished even without conversion. For details, refer to Types of Keyword Search in Kuroco.
Options used for conversion
mb_convert_kana can be used as a Smarty modifier in the form |mb_convert_kana:'options'.
The following is an example with KVCas specified.
| Option | Conversion | Example |
|---|---|---|
K V | Converts half-width katakana to full-width katakana (V merges voiced/semi-voiced sound marks into one character) | ガイド → ガイド |
C | Converts full-width hiragana to full-width katakana | がいど → ガイド |
a | Converts full-width alphanumeric characters and symbols to half-width | ABC123<> → ABC123<> |
s | Converts full-width spaces to half-width spaces | → |
Converting the search string in the keyword template
On the content definition edit screen, check "Use template for keyword search" and specify mb_convert_kana for the values output in "Keyword template".
The following example converts and outputs the title and the content.
{* Title *}
{$details.subject|mb_convert_kana:'KVCas'|escape}
{* Content *}
{$details.contents|strip_tags|mb_convert_kana:'KVCas'|escape}
For how to set up the keyword template, refer to Prepare a keyword search string.
The search strings of registered content are updated based on the keyword template by the topics_keyword batch (every hour). For details, refer to Default Batch Processing List.
Converting the search keyword in pre-processing
In the pre-processing of the content list endpoint, convert the requested full_text_search with the same options as the keyword template.
{assign_array var="request" values=""}
{if $smarty.get.full_text_search}
{assign
var="request.full_text_search"
value=$smarty.get.full_text_search|mb_convert_kana:'KVCas'}
{/if}
Once the custom function is linked to the pre-processing of the endpoint, requests with full_text_search=がいど or full_text_search=ガイド also return content containing ガイド.
For how to set up pre-processing, refer to Overwriting request values passed to API main processes using custom functions.
Related documents
Support
If you have any other questions, please contact us or check out Our Slack Community.