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 Name | Content |
---|---|
Name | Lecture |
Method of entering the main text | Text area |
Use template for keyword search | Check [Enable] |
Fields
Field Name | Field Settings | Item Setting Options |
---|---|---|
Presenter | Select related information | Module: Member |
Date and Time | Date format | Also set the time (hh:mm) |
Theme | Text | |
Online Streaming | Single choice | Required input Use radio buttons 0: No online streaming 1: Online streaming available |
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 Name | Identifier | Settings |
---|---|---|
Public Profile | publish_profile | Text area |
Set the target string for search
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.
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 Name | Type | Description |
---|---|---|
$details | Object | Content details |
$ext_config | Object | Content 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}
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.
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.
It may take a few minutes for the changes to take effect.
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.
The "Keyword Template" option will not be displayed until the changes are reflected.
In this example, the displayed string will be as follows.
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.
- 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:
- Path: search
- Category: Content
- Model: Topics, v1
- Operation: list
- topics_group_id: 83 (the ID assigned in Create a content structure)
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.
When specifying multiple keywords separated by spaces, the AND/OR conditions can be set with the full_text_search_cond
parameter. If not specified, it operates as AND by default.
Related Documents
Support
If you have any other questions, please contact us or check out Our Slack Community.