As discussed:

1. Move 7.x module to repository in a new branch
2. Merge integration into the main module, do minimal 8.x port (PSR-4 and so on)
3. Possibly postpone further work on having a working server.

Support from Acquia helps fund testing for Drupal Acquia logo

Comments

Berdir’s picture

Assigned: Berdir » Unassigned
Status: Active » Postponed

Pushed the code to the views branch. Doesn't work as hook_views_data() has not been ported yet, but it has been renamed, so it will fatal error.

Maybe we can start with a very simple definition that only comes with a fulltext argument and rendered entities? Postponed until we have a working backend....

Berdir’s picture

Made some more progress, made a simplistic hook_views_data() work and the query is now executed, I can display some entities with the test backend, looking forward to see the db backend working :)

Everything very minimalistic of course, there's a *lot* to do, but this is a good start I think :)

Berdir’s picture

Status: Postponed » Needs review
FileSize
128.88 KB

Ok, here is a patch for review, at least the changes outside of views related code. Not sure how useful it is to review the views specific code, maybe the query implementation and the plugins that work: SearchApiRow, SearchApiMoreLikeThis, SearchApiFulltext.

What's working:
- Creating entities with display "Rendered Search API items"
- Multiple data sources
- Exposed fulltext argument
- More like this contextual filter (not supported by the database server I think?)

Berdir’s picture

Updated patch with a few fixes and a working test.

Added a trait to share code with the Db backend test for creating example content and stuff.

drunken monkey’s picture

Component: Backend » Framework

Wow, our first trait, great!
Also, great work otherwise, looks very good! And since I already saw it work, even better!
Just a few remarks:

  1. +++ b/search_api.api.php
    @@ -319,5 +319,34 @@ function hook_search_api_index_reindex(\Drupal\search_api\Index\IndexInterface $
      */
    +
    diff --git a/search_api.views.inc b/search_api.views.inc
    

    Superfluous newline.

  2. +++ b/src/Entity/Index.php
    @@ -1084,6 +1084,16 @@ class Index extends ConfigEntityBase implements IndexInterface {
    +          $this->invalidateViewsCache();
    +        }
    +        // Check whether the indexed fields changed.
    +        if ($this->original->getFields() != $this->getFields()) {
    +          views_invalidate_cache();
    

    Is there a reason why you use the function directly, instead of the method, in the latter case?

  3. +++ b/src/Entity/Index.php
    @@ -1172,10 +1182,32 @@ class Index extends ConfigEntityBase implements IndexInterface {
    +   * Function for reacting to a disabled or deleted search index.
    +   */
    +  protected function invalidateViewsCache() {
    

    Is this correct? Wouldn't it allow the user to create a new view for a deleted index after an index has been deleted (or with fields not available anymore)? Or is the Views cache automatically cleared when creating a new view (or enabling a disabled one)?

  4. +++ b/src/Plugin/views/argument/SearchApiArgument.php
    @@ -0,0 +1,154 @@
    + * @file
    + * Contains SearchApiViewsHandlerArgument.
    

    Needs to be namespaced, and name is not up to date.
    Also, why does this need a module prefix? Is there some special rule, or only because "Argument" alone would sound stupid? Maybe "SearchArgument" then?

  5. +++ b/src/Query/QueryInterface.php
    @@ -165,7 +165,9 @@ interface QueryInterface {
    -   *     the items' IDs, values are arrays containing the following keys:
    +   *     the concatenated datasource and the ID, the delimiter is
    +   *     IndexInterface::DATASOURCE_ID_SEPARATOR, values are arrays containing
    +   *     the following keys:
    

    This shouldn't be documented in every single instance where IDs are used. We should probably give some thought to where to best explain this, but for now just use "internal item IDs", or an additional "(with datasource ID)" if you want to clarify.
    But in general, we use these combined IDs nearly everywhere now, except in the datasource itself (and some index code dealing with datasources, of course), so even that clarification shouldn't be necessary.

  6. +++ b/src/Tests/ExampleContentTrait.php
    @@ -0,0 +1,223 @@
    +/**
    + * Contains \Drupal\search_api\Tests\TestDataTrait.
    + */
    

    Missing "@file" and correct name.

  7. +++ b/src/Tests/ExampleContentTrait.php
    @@ -0,0 +1,223 @@
    +
    +} ¶
    diff --git a/src/Tests/SearchApiViewsTest.php b/src/Tests/SearchApiViewsTest.php
    

    Trailing space.

  8. +++ b/tests/modules/search_api_test_backend/search_api_test_backend.info.yml
    @@ -2,8 +2,7 @@ name: 'Search API Test Backend'
    -version: VERSION
    

    This is also used in libraries.yml, and I already wondered. Is it correct there?

drunken monkey’s picture

Status: Needs review » Needs work
Berdir’s picture

Status: Needs work » Needs review
FileSize
148.06 KB
7.83 KB

Thanks for the review.

1. Fixed.
2. I tried to port the logic from the 7.x hooks, but after thinking more about it, it was quite flawed (almost all changes can affect the views data, doesn't really matter if we have views on it or not and disabling affects it just as much as enabling an index...). So, I simplified it to always clear the views cache on postSave() and preDelete().
3. See above.
4. As discussed, @amateescu and me both preferred to have some sort of prefix (not as a module name but as a concept) to separate the search api plugins from the standard ones.
5. Yeah, I did initially rely on it and it was different between the test and database backend (both were incomplete), that's why I added some documentation. Simplified it a bit and just mention it's a unique identifier including the datasource, to make sure that you can't just use it as the item ID anymore, like the old views query implementation used to do.
6. Fixed.
7. Yeah, I'm not sure about libraries.yml, that's an interesting point, probably doesn't matter much if it's internal, but it's wrong in both, only core is allowed to use that constant I think.

Also fixed the broken tests, will merge when it passes...

Berdir’s picture

Status: Needs review » Fixed

Committed!

  • Commit c6ff385 on master by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

Status: Fixed » Closed (fixed)

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

  • Commit c6ff385 on master, htmlfilter by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder, 2230881-test-all-processors by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder, issue-2273743 by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, 2235381-fix-config-schemas, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2 by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema, transliteration by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema, transliteration, ignore-case-test-fix by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema, transliteration, ignore-case-test-fix, 2281233-fix-stopwords by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema, transliteration, ignore-case-test-fix, 2281233-fix-stopwords, ignorecase-nick, renamefields by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, move-integration-tests-subfolder, issue-2273743, 2268885-fix-validation, synonyms-processor, 2230925-server-tasks, 2235381-fix-config-schemas-2, 2257113-Index-Processors-Fields, config-schema, transliteration, ignore-case-test-fix, 2281233-fix-stopwords, ignorecase-nick, renamefields by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, issue-2273743, 2268885-fix-validation, synonyms-processor, 2235381-fix-config-schemas-2, config-schema, transliteration, ignore-case-test-fix, ignorecase-nick, renamefields, highlight by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, issue-2273743, 2268885-fix-validation, synonyms-processor, 2235381-fix-config-schemas-2, config-schema, transliteration, ignore-case-test-fix, ignorecase-nick, renamefields, highlight, add-aggregation-nick by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, issue-2273743, 2268885-fix-validation, synonyms-processor, 2235381-fix-config-schemas-2, config-schema, transliteration, ignore-case-test-fix, ignorecase-nick, renamefields, highlight, add-aggregation-nick, 2247923-Test_the_RenderedItem_processor by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.
    

  • Commit c6ff385 on master, htmlfilter, issue-2273743, 2268885-fix-validation, synonyms-processor, 2235381-fix-config-schemas-2, config-schema, transliteration, ignore-case-test-fix, ignorecase-nick, renamefields, highlight, add-aggregation-nick, 2247923-Test_the_RenderedItem_processor, 2286813-fields-processor-plugin-base-test by Berdir:
    Issue #2252171 by Berdir: Added initial Views integration.