0

I'm currently implementing a custom search engine in my custom module. In order to optimize my module, I would like to perform SQL queries by using the syntax MATCH....AGAINST in Entity queries.

By reading the Drupal 8 documentation, i've didn't find any solutions or example for my purpose. I've two questions :

1) How it is possible to add a FULLTEXT index in my custom schema ?

enter image description here

Here an example of my schema set in my_module.install file

function document_search_schema()
{
  $schema['document_search_content'] = [
    'description' => 'Document content',
    'fields' => [
      'id' => array(
        'description' => 'The primary identifier for the record',
        'type' => 'serial',
        'unsigned' => TRUE,
        'not null' => TRUE
      ),
      'mid' =>[
        'description' => 'Primary key: {media}.mid for media',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE,
        'default' => 0
      ],
      'node_field_data_nid' =>[
        'description' => 'Primary key: {node_field_data}.nid for node_field_data',
        'type' => 'int',
        'unsigned' => TRUE,
        'not null' => TRUE
      ],
      'node_field_data_langcode' =>[
        'description' => 'Primary key: {node_field_data}.langcode for node_field_data',
        'type' => 'varchar',
        'length' => 255,
        'not null' => TRUE
      ],
      'name' => [
        'description' => 'Title of document',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'normal',
      ],
      'content' => [
        'description' => 'Content of document',
        'type' => 'text',
        'not null' => TRUE,
        'size' => 'big',
      ]
    ],
    'foreign keys' => array(
      'fk_node_field_data' => array(
        'table' => 'node_field_data',
        'columns' => array(
          'nid' => 'nid',
          'langcode' => 'langcode'
        ),
      ),
      'fk_media' => array(
        'table' => 'media',
        'columns' => array(
          'mid' => 'mid',
        ),
      ),
    ),
    'primary key' => ['id'],
  ];

  return $schema;
}

2) Then, which syntax do I need to use to search a text by using the syntax MATCH ... AGAINST ?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.