Skip to main content

Prepare a keyword search string

Overview

In addition to the content items, you can prepare a string for full-text searches.
The string for full-text searches can be set using Smarty in the keyword template of the content structure, so you can add or delete strings to be used for searches from the registered content, and add other content or member information associated with the content as strings for searches.
In addition, by using only this template for keyword searches, the performance of the search will be improved.

This time, we will set it so that the profiles of members associated with the content will be the search target, focusing on the schedule of a lecture.

What you can learn

We will configure and verify the keyword template using the following steps.

Prepare the content

Set the necessary items for the content and members.

Create a content structure

Refer to Creating Content structure to create a content structure that will be the target of full-text searches.
This time, assuming the schedule of a lecture, we created the following content structure.

Basic items

Item NameContent
NameLecture
Method of entering the main textText area
Use template for keyword searchCheck [Enable]

Fields

IDField NameIdentifierField SettingsItem Setting Options
01PresenterpresenterSelect related informationModule: Member
02Date and TimedateDate formatAlso set the time (hh:mm)
03ThemethemeText
04Online StreamingstreamingSelection formatRequired input
Use radio buttons
0: No online streaming
1: Online streaming available

Image from Gyazo

Configure member extended items

Refer to Extended item settings and List of extension items in member detailed settings. to configure the items. This time, assuming the presenter of the lecture, we added the following extended item.

Fields

Item NameIdentifierSettings
Public Profilepublish_profileText area

Image from Gyazo

Check the search target string template

By default, the following are entered as templates that will be the search targets:

  • topics_id
  • slug
  • Title
  • Content
  • Category
  • Text part of all extended items.
info

If you want to return to the initial state, update it with an empty value and the default template will be automatically entered.

Reference

The available variables are as follows.

Variable NameTypeDescription
$detailsObjectContent details
$ext_configObjectContent extension settings

The text output by Smarty's description will be the target of full-text search.

Modifying the Search Target String Template

Modify the template of the content structure added in "Create a content structure". In this example, the following items are added to the search target string:

  • Title
  • Name and public profile of member information associated with related information
  • Formatted date and time of the event
  • Theme
  • Label for online streaming

For information on retrieving member information associated with related information, refer to "CCan I call Kuroco's API from custom function?".

Delete all default settings and write as follows:

{* Title *}
{$details.subject|escape}

{* Presenter *}
{if $details.presenter.module_type eq 'member' && $details.presenter.module_id}
{capture name=method_params}{ldelim}
"filter": "member_id eq {$details.presenter.module_id}"
{rdelim}{/capture}
{assign var=method_params value=$smarty.capture.method_params|json_decode:1}
{api_method
var=member_list
model="Member"
method="list"
version="1"
method_params=$method_params
}
{foreach from=$member_list.list item=member}
{* Name *}
{$member.name1|escape} {$member.name2|escape}
{* Public Profile *}
{$member.publish_profile|escape}
{/foreach}
{/if}

{* Date and Time *}
{$details.date|strtotime|date_format:"Y/m/d H:i"}
{$details.date|strtotime|date_format:"d-M-Y H:i"}

{* Theme *}
{$details.thema|escape}

{* Online Streaming *}
{if $details.streaming.key > 0}
{$details.streaming.label}
{/if}

{* Content *}
{$details.contents|strip_tags|escape}

Image from Gyazo

Saving the Search Target String Template

After completing the description, click the "Update" button to save it. The configuration is now complete.

When adding or updating content, the search target string will be automatically saved based on the template.

caution

It may take a few minutes for the changes to take effect.

Confirming the Operation

Add content and check the search results from Swagger UI.

Adding Content

Add content according to the content structure created in "Creating Content structures".

Enter the content in the form and click the "Add" button to add the content. When adding or updating content, the search target string will be automatically saved based on the template.

caution

It may take a few minutes for the changes to take effect.

Image from Gyazo

Checking the Search Target String

In the editing screen of the added content, click the "Other" button to display the options. Click "Keyword Template" to check the output search target string.

Image from Gyazo

caution

The "Keyword Template" option will not be displayed until the changes are reflected.

In this example, the displayed string will be as follows.
Image from Gyazo

tip

If the search target string contains HTML tags, the HTML tags themselves will also be included in the search target. If you want to search without HTML tags, consider using the strip_tags modifier.

info
  • The searchable character string that can be generated is limited to 100MB per content (equivalent to over 30 million characters assuming 3 bytes per multibyte character), and any string exceeding 100MB will be truncated.
  • Half-width English letters within the searchable character string generated by templates will be automatically converted to lowercase.

Prepare the Full-Text Search Endpoint

Prepare an endpoint for searching.

Refer to Configuring endpoints to create a content structure to be used for full-text search.

This time, set the path and model as follows:

Image from Gyazo

Check with Swagger UI

Send a request to the endpoint added in [Prepare the Full-Text Search Endpoint] from the Swagger UI screen. By entering a keyword in full_text_search, only the contents that include the keyword in the full-text search string will be returned.

Image from Gyazo


Support

If you have any other questions, please contact us or check out Our Slack Community.