When enabling Search API and Search API DB and you go to the configuration, you still have to select and click around. We discussed this offline and it would make sense to have sensible defaults (similar to Core Search) and some search pages based on Search API DB. Each backend can configure this for itself, and we should lead by example and do this for Search API DB.

Thoughts?

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

drunken monkey’s picture

Would this then happen completely automatically when enabling the module? Or what's the idea?
What I could imagine, when there is neither an index nor a server yet, having a button on the Search API admin overview page for creating a default setup. This could then also have simple configuration, if really necessary (multiple backends are available, or the backend cannot provide a default for some setting).

However, if we do this now it should be light-weight and self-contained enough to be easily ripped out again later if we come up with a more holistic approach to user-friendliness (i.e., #2387893: Overhaul administration UI).

Nick_vh’s picture

Status: Active » Needs review
FileSize
7.7 KB

Very simple patch attached that does not add any code, only configs. 1 test is failing here, so trying to figure out why.

Nick_vh’s picture

The idea is that this indeed happens automatically, similar to other "Extensions" and Drupal itself as well. It's easy to remove them if you do no need them. I'm not sure if there is a need for a button if there is nothing. One could import the configs from the install or reinstall the module completely if there is nothing anyway.

Shipping default configs seems light-weight to me, and easily updateable and changeable, so I don't see much risk.

Status: Needs review » Needs work

The last submitted patch, 2: search-api-defaults_2470874.patch, failed testing.

Nick_vh’s picture

reroll

Nick_vh’s picture

Status: Needs work » Needs review

Status: Needs review » Needs work

The last submitted patch, 5: search-api-defaults_2470874-5.patch, failed testing.

drunken monkey’s picture

Shipping default configs seems light-weight to me, and easily updateable and changeable, so I don't see much risk.

Automatically creating a server when enabling the Database Search module does make sense, yes.
However, while we initially planned to do it, it's completely impossible to have a default index or search page as configuration, as you don't know which datasources will be available. Not even the Node module is required anymore, so even doing a default node index isn't possible anymore, without code checking whether the module is there.

So, I totally agree with having a default server in the Database module, but anything else would be significantly more complex.

Nick_vh’s picture

At @drupaldevdays in Montpellier we discussed a couple of approaches and we settled on a submodule that depends on search_api and search_api_db and node since we will ship with sensible defaults that index your node. This should not be called example as it should be ok for sites to depend on it. the consensus initially is search_api_db_defaults.

This allows us to put plain exports in there and keep it very very lightweight. This can also serve as an example for other backend modules to ship defaults. This also allows power-users to not enable this module and start with a clean slate.

Nick_vh’s picture

FileSize
0 bytes
Nick_vh’s picture

Status: Needs work » Needs review

We also want some messaging in the index/server listing if you haven't enabled the module and there are no indexes or servers configured. We should help users to get started. Missing here is the view that sets up the search page for nodes and users, similar to what core search ships with.

Nick_vh’s picture

Nick_vh’s picture

FileSize
8.98 KB

I'm being stupid. Going to add the views now

drunken monkey’s picture

Status: Needs review » Needs work

Looks good so far, thanks!
The view is of course still missing (the module should then just also depend on Views, though), also I saw these little issues:

  1. +++ b/search_api_db/search_api_db_defaults/config/install/search_api.index.search_api_database_index.yml
    @@ -0,0 +1,189 @@
    +uuid: 62dd515d-ccc7-4304-8000-c13ce6aed478
    

    Default config should never have UUIDs, as far as I now.

  2. +++ b/search_api_db/search_api_db_defaults/config/install/search_api.server.server.yml
    @@ -0,0 +1,76 @@
    +  min_chars: 1
    

    Is 1 really the best default here? I think 3 will usually make more sense.
    We do already have that on the Tokenizer, though, so it should probably not matter much (except for numeric tokens, I think?).

  3. +++ b/src/IndexListBuilder.php
    @@ -150,7 +150,7 @@ class IndexListBuilder extends ConfigEntityListBuilder {
    +      '#empty' => $entity_groups['lone_indexes'] ? '' : $this->t('There are no servers or indexes defined. For a quick start, we suggest you install the Search API Database Defaults module.'),
    

    Maybe link that to the Modules page?

Nick_vh’s picture

Regarding 2, we should revise our defaults then as I did not adjust that value manually

drunken monkey’s picture

Hm, yes, I guess that would make sense. Using "1" as the default seemed the most natural selection, since all others are more arbitrary choices, but I guess having a sensible default (at least for English) is still better.

Nick_vh’s picture

drunken monkey’s picture

FileSize
21.29 KB
23.41 KB
Nick_vh’s picture

@todo : Create simple test that installs this module and checks if

* the views page is there.
* the view modes are there
* the index is there
* the server is there

Nick_vh’s picture

Status: Needs work » Needs review
FileSize
12.81 KB
29.02 KB

Added those tests and also attached is an interdiff

Nick_vh’s picture

  1. +++ b/search_api_db/search_api_db_defaults/src/Tests/IntegrationTest.php
    @@ -34,18 +38,11 @@ class IntegrationTest extends WebTestBase {
    +  protected $anonymousUser;
    

    duh - not an anonymous user if we create a user object. This should be renamed to authenticatedUser and we should test with anonymous and with authenticated to see if the view is accessible to both.

  2. +++ b/search_api_db/search_api_db_defaults/src/Tests/IntegrationTest.php
    @@ -53,21 +50,71 @@ class IntegrationTest extends WebTestBase {
    +    // Create Basic page and Article node types.
    

    perhaps change types to bundles?

Nick_vh’s picture

Additionally, I was curious why the view initially exported with views_query as the query plugin for the view instead of with search_api_query. This caused the view unable to import as config to the system and the worst part was that it doesn't show any error. This might even be a drupal core bug, needs further investigation and steps to reproduce.

drunken monkey’s picture

Status: Needs review » Needs work
FileSize
28.46 KB

Sorry for the long delay, was very busy unfortunately.
The patch looks already very good, but needed a re-roll. I also found these problems:

  1. +++ b/config/schema/search_api.views.schema.yml
    @@ -4,10 +4,13 @@ views.query.search_api_query:
    +      label: If the underlying search index has access checks enabled, this option allows you to disable them for this view
         entity_access:
           type: boolean
    +      label: Execute an access check for all result entities.
         parse_mode:
           type: string
    +      label: Chooses how the search keys will be parsed
    

    See #2473757: Only sentences should end with periods.

  2. +++ b/search_api_db/config/schema/search_api_db.backend.schema.yml
    @@ -5,6 +5,9 @@ search_api.backend.plugin.search_api_db:
    +    database_text:
    

    Why include that? I don't think that should ever be in the options, we only use that key for display purposes when editing the server.
    If this results in a value saved in the options, it's definitely a bug (even sounds like one in Core?), and in any case nothing we should replicate in our default configuration.

Regarding your own two remarks in #21: do you want to still implement them here, or should I commit and we'll make a follow-up?
Anyways, patch attached. Set to "Needs work", though, because before #2473717: Add support for per-bundle view modes in the rendered entity processor gets fixed again it will fail anyways.

drunken monkey’s picture

Status: Needs work » Needs review

The last submitted patch, 18: 2470874-18--default_configs.patch, failed testing.

drunken monkey’s picture

OK, I just implemented your two suggestions. As I did, I noticed I hadn't reviewed the new test class before. So I also made these changes:

  1. +++ b/search_api_db/search_api_db_defaults/src/Tests/IntegrationTest.php
    @@ -80,36 +80,9 @@ class IntegrationTest extends WebTestBase {
    -  /**
    -   * Create article and page bundle with their necessary fields for our default
    -   * configuration.
    -   */
    -  private function createNodeBundles() {
    +  protected function createNodeBundles() {
    

    The first sentence of a doc block should always be on its own line and never exceed 80 characters (including the * preceding it).

    Also, methods should almost never be private.

  2. +++ b/search_api_db/search_api_db_defaults/src/Tests/IntegrationTest.php
    @@ -196,9 +171,26 @@ class IntegrationTest extends WebTestBase {
    +   * Tests whether the default search was correctly installed.
    +   */
    +  protected function testDefaultSetupWorking() {
    +    $server = Server::load('default_server');
    +    $this->assertTrue($server, 'Server can be loaded');
    +
    +    $index = Index::load('default_index');
    +    $this->assertTrue($index, 'Index can be loaded');
    +
    +    $this->drupalGet('search/content');
    +    $this->assertResponse(200, 'Anonymous user can access the search page.');
    +    $this->drupalLogin($this->authenticatedUser);
    +    $this->drupalGet('search/content');
    +    $this->assertResponse(200, 'Authenticated user can access the search page.');
    +  }
    

    Since each test method means a complete site install, for performance reason I always try to stick with a single test method (aside from PHPUnit tests).

  3. +++ b/search_api_db/search_api_db_defaults/src/Tests/IntegrationTest.php
    @@ -210,8 +202,11 @@ class IntegrationTest extends WebTestBase {
    +   *
    +   * @return \Drupal\field\Entity\FieldConfig
    +   *   The newly created field configuration.
    

    Copying bad code from Core is no excuse to skip the @return tag. ;P

The attached patch is RTBC for me. If the test bot agrees and no-one objects, I'll commit it.

drunken monkey’s picture

Status: Needs review » Fixed

Wow, that was quick! The test bot speed on weekends is insane …
So, since the test bot is happy: committed.
Thanks a lot again, Nick!
(If someone wants to object after all, please re-open!)

  • drunken monkey committed 381b3c7 on 8.x-1.x authored by Nick_vh
    Issue #2470874 by Nick_vh, drunken monkey: Added a module for deploying...

Status: Fixed » Closed (fixed)

Automatically closed - issue fixed for 2 weeks with no activity.

LKS90’s picture

Issue summary: View changes
Status: Closed (fixed) » Needs work
Related issues: +#2510564: Indexing is broken
FileSize
60.35 KB

With this patch the search_api.index.default_index.yml was committed which is currently not correct and makes the search_api_db_defaults useless.
Here is a screenshot of the database, tables and fields which this config produces on a fresh install:

Every field after the entity:node/title one is missing, which causes errors when indexing as it tries to insert values into a non-existent column.
Here is the issue I created a while back when I initially noticed the issue: #2510564: Indexing is broken
We can probably fix the config in that issue.

drunken monkey’s picture

If there is already an issue, why did you re-open this one?

LKS90’s picture

Status: Needs work » Closed (fixed)
Issue tags: +needs test

Sorry, will do the work in the other issue and close this one.

tim.plunkett’s picture

Issue tags: -needs test