1

Like i said in the title, i dont know how the Search in Catalog work.

As far as i know, the Search is render through this code in this ui-component:

C:\xampp\htdocs\magento\vendor\magento\module-cms\view\adminhtml\ui_component\cms_page_listing.xml

<filterSearch name="fulltext"/>

And when i copy this code and paste to my ui-component, it doesn't work at all, i can render the search text box, but when i write something and push "Enter", nothing happened.

enter image description here

EDIT 1:

(Here is my ui-component, InstallSchema and UpgradeSchema file)

File : C:\xampp\htdocs\magento\app\code\Aht\BannerSlider\view\adminhtml\ui_component\banner_form.xml

<?xml version="1.0" encoding="UTF-8"?>
<!--
/**
 * Copyright © Magento, Inc. All rights reserved.
 * See COPYING.txt for license details.
 */
-->
<form xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:noNamespaceSchemaLocation="urn:magento:module:Magento_Ui:etc/ui_configuration.xsd">
    <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="provider" xsi:type="string">banner_form.banner_form_data_source</item>
        </item>
        <item name="label" xsi:type="string" translate="true">General Information</item>
        <item name="template" xsi:type="string">templates/form/collapsible</item>
    </argument>
    <settings>
        <buttons>
            <button name="save_and_continue" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\SaveAndContinueButton"/>
            <button name="save" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\SaveButton"/>
            <button name="reset" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\ResetButton"/>
            <button name="delete" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\DeleteButton"/>
            <button name="back" class="Aht\BannerSlider\Block\Adminhtml\Banner\Edit\BackButton"/>
        </buttons>
        <namespace>banner_form</namespace>
        <dataScope>data</dataScope>
        <deps>
            <dep>banner_form.banner_form_data_source</dep>
        </deps>
    </settings>
    <dataSource name="banner_form_data_source">
        <argument name="data" xsi:type="array">
        <item name="js_config" xsi:type="array">
            <item name="component" xsi:type="string">Magento_Ui/js/form/provider</item>
        </item>
    </argument>
        <settings>
            <submitUrl path="banner/manage/save"/>
        </settings>
        <dataProvider class="Aht\BannerSlider\Model\Banner\DataProvider" name="banner_form_data_source">
            <settings>
                <requestFieldName>id</requestFieldName>
                <primaryFieldName>id</primaryFieldName>
            </settings>
        </dataProvider>
    </dataSource>
    <fieldset name="general">
        <settings>
            <label/>
        </settings>
        <field name="id" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">banner</item>
                </item>
            </argument>
            <settings>
                <dataType>text</dataType>
                <visible>false</visible>
                <dataScope>id</dataScope>
            </settings>
        </field>
        <field name="name" sortOrder="20" formElement="input">
            <argument name="data" xsi:type="array">
                <item name="config" xsi:type="array">
                    <item name="source" xsi:type="string">banner</item>
                </item>
            </argument>
            <settings>
                <validation>
                    <rule name="required-entry" xsi:type="boolean">true</rule>
                </validation>
                <dataType>text</dataType>
                <label translate="true">Banner Name</label>
                <dataScope>name</dataScope>
            </settings>
        </field>
    </fieldset>
</form>

File: InstallSchema.php

class InstallSchema implements \Magento\Framework\Setup\InstallSchemaInterface
{

public function install(\Magento\Framework\Setup\SchemaSetupInterface $setup, \Magento\Framework\Setup\ModuleContextInterface $context)
{
    $installer = $setup;
    $installer->startSetup();
    if (!$installer->tableExists('banner')) {
        $table = $installer->getConnection()->newTable(
            $installer->getTable('banner')
        )
            ->addColumn(
                'id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                [
                    'identity' => true,
                    'nullable' => false,
                    'primary'  => true,
                    'unsigned' => true,
                ],
                'ID'
            )
            ->addColumn(
                'name',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                ['nullable => false'],
                'Name'
            )
            ->addColumn(
                'created_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                'Created At'
            )->addColumn(
                'updated_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                'Updated At')
            ->setComment('Banner Table');
        $installer->getConnection()->createTable($table);
    }

    if (!$installer->tableExists('slide')) {
        $table = $installer->getConnection()->newTable(
            $installer->getTable('slide')
        )
            ->addColumn(
                'id',
                \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                null,
                [
                    'identity' => true,
                    'nullable' => false,
                    'primary'  => true,
                    'unsigned' => true,
                ],
                'ID'
            )
            ->addColumn(
                'banner_id',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'Banner Id'
            )
            ->addColumn(
                'name',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                ['nullable => false'],
                'Name'
            )
            ->addColumn(
                'url',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'URL'
            )
            ->addColumn(
                'image',
                \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                255,
                [],
                'Image'
            )
            ->addColumn(
                'created_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                'Created At'
            )->addColumn(
                'updated_at',
                \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                null,
                ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                'Updated At')
            ->setComment('Slide Table');
        $installer->getConnection()->createTable($table);
    }

    $installer->endSetup();
}
}


File: UpgradeSchema.php

<?php
namespace Aht\BannerSlider\Setup;

use Magento\Framework\Setup\UpgradeSchemaInterface;
use Magento\Framework\Setup\SchemaSetupInterface;
use Magento\Framework\Setup\ModuleContextInterface;

class UpgradeSchema implements UpgradeSchemaInterface
{
    public function upgrade( SchemaSetupInterface $setup, ModuleContextInterface $context ) {
        $installer = $setup;

    $installer->startSetup();

    if(version_compare($context->getVersion(), '1.1.0', '<')) {

        if (!$installer->tableExists('banner_slide')) {
            $table = $installer->getConnection()->newTable(
                $installer->getTable('banner_slide')
            )
                ->addColumn(
                    'id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    [
                        'identity' => true,
                        'nullable' => false,
                        'primary'  => true,
                        'unsigned' => true,
                    ],
                    'ID'
                )
                ->addColumn(
                    'banner_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['nullable => false'],
                    'Banner ID'
                )
                ->addColumn(
                    'slide_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['nullable => false'],
                    'Slide ID'
                )
                ->addColumn(
                    'created_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                    'Created At'
                )->addColumn(
                    'updated_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                    'Updated At')
                ->setComment('Banner Slide Table');

            $installer->getConnection()->createTable($table);
        }

        if (!$installer->tableExists('banner_page')) {
            $table = $installer->getConnection()->newTable(
                $installer->getTable('banner_page')
            )
                ->addColumn(
                    'id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    [
                        'identity' => true,
                        'nullable' => false,
                        'primary'  => true,
                        'unsigned' => true,
                    ],
                    'ID'
                )
                ->addColumn(
                    'banner_id',
                    \Magento\Framework\DB\Ddl\Table::TYPE_INTEGER,
                    null,
                    ['nullable => false'],
                    'Banner ID'
                )
                ->addColumn(
                    'page_url',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TEXT,
                    255,
                    ['nullable => false'],
                    'Page Url'
                )
                ->addColumn(
                    'created_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT],
                    'Created At'
                )->addColumn(
                    'updated_at',
                    \Magento\Framework\DB\Ddl\Table::TYPE_TIMESTAMP,
                    null,
                    ['nullable' => false, 'default' => \Magento\Framework\DB\Ddl\Table::TIMESTAMP_INIT_UPDATE],
                    'Updated At')
                ->setComment('Banner Page Table');

            $installer->getConnection()->createTable($table);
        }

        if ($installer->tableExists('slide')){
            $connection = $installer->getConnection();
            $tableName = $installer->getTable('slide');
            $columnName = 'banner_id';
            if($connection->tableColumnExists($tableName,$columnName, $schemaName = null)){
                $connection->dropColumn($tableName, $columnName, $schemaName = null);
            }
        }
    }

    $installer->endSetup();
}
}

EDIT 2 (fixed in EDIT 3):

I'm following Marius solution.

But it doesn't seem to work. It throw an error when i'm trying "php bin/magento setup:upgrade"

Installing schema... Upgrading schema... SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.banner_name' doesn't exist, query was: DESCRIBE BANNER_NAME

So here is what i update to UpdateSchema.php.

if ($installer->tableExists('banner')){
            $connection = $installer->getConnection();
            $connection->addIndex(
                    $setup->getIdxName(
                        $installer->getTable('banner'),
                        ['name'],
                        AdapterInterface::INDEX_TYPE_FULLTEXT
                    ),
                    ['name'],
                    ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
                );
        }

EDIT 3:

So i was trying Marius solution like this (the difference is i give it a table in "addIndex" function):

if ($installer->tableExists('banner')){
            $connection = $installer->getConnection();
            $connection->addIndex(
                $installer->getTable('banner'),
                $setup->getIdxName(
                    $installer->getTable('banner'),
                    ['name'],
                    AdapterInterface::INDEX_TYPE_FULLTEXT
                ),
                ['name'],
                AdapterInterface::INDEX_TYPE_FULLTEXT
            );
        }

Also, before i do that, i have to clear cache and delete my module in "setup_module" table, and it work. But for some reason, when i click "x" to clear the search, it throw 2 column exactly like the same( look the image below): enter image description here

1 more problem is i cant search with "c". I've read some where that "fulltext_search" cant be use with 5 or less character. So there are any solution to fix this?

9
  • In which module it's not working? Commented Aug 1, 2018 at 7:35
  • Thanks for reply, i'm trying to do the search, so the one is not working is my module. I'll edit the post so you can see my ui-component. :)
    – fudu
    Commented Aug 1, 2018 at 7:47
  • Edited, please check :D
    – fudu
    Commented Aug 1, 2018 at 7:49
  • can you post your InstallSchema.php file in here ?
    – Marius
    Commented Aug 1, 2018 at 7:52
  • Ok, hold on, i'm editing
    – fudu
    Commented Aug 1, 2018 at 7:56

1 Answer 1

4

The general search field in the grid works with full text search indexes. Your table does not have any, that's why nothing happens.
You need to add to your table a full text index that indexes all the fields you want searched.
Here is an example from the cms module

->addIndex(
        $setup->getIdxName(
            $installer->getTable('cms_block'),
            ['title', 'identifier', 'content'],
            AdapterInterface::INDEX_TYPE_FULLTEXT
        ),
        ['title', 'identifier', 'content'],
        ['type' => AdapterInterface::INDEX_TYPE_FULLTEXT]
);

This means that you are creating a full text index on the fields title, identifier and content for the cms block entity.

8
  • well , I'm trying to follow your code, but it return an error " Installing schema... Upgrading schema... SQLSTATE[42S02]: Base table or view not found: 1146 Table 'magento.banner_name' doesn't exist, query was: DESCRIBE BANNER_NAME "
    – fudu
    Commented Aug 1, 2018 at 8:39
  • I was replaced "cms_block" with "banner" and " 'title', 'identifier', 'content' " with "name". That's all.
    – fudu
    Commented Aug 1, 2018 at 8:40
  • I've updated the code, please check
    – fudu
    Commented Aug 1, 2018 at 8:52
  • I have no idea where that banner_name comes from.
    – Marius
    Commented Aug 1, 2018 at 8:57
  • hmmm .. This is weird @@ incase you wanna know the code, i've update the UpgradeSchema.php in my post.
    – fudu
    Commented Aug 1, 2018 at 9:00

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.