Problem/Motivation
The issue https://www.drupal.org/project/search_api/issues/3115214 defined a method to index items on behat using the tag @search_api.
The reason for using the tag is because search_api enqueue the content that needs indexation with the service search_api.post_request_indexing and until the PHP process is not finished, it does not index the content because this service does it on its destruct method, so using the tag @search_api we call to the destruct method.
See the code in https://git.drupalcode.org/project/search_api/-/blob/8.x-1.x/search_api....
* @AfterStep
*/
public function indexEntities(AfterStepScope $event) {
$tags = $event->getFeature()->getTags();
if (!in_array('search_api', $tags)) {
return;
}
\Drupal::getContainer()->get('search_api.post_request_indexing')
->destruct();
}
We added the tag '@search_api' to index the content created in the scenario, but debugging, the method ```$event->getFeature()->getTags();``` returns empty tags, so the destruct is never called, so the items are not indexed during the scenario execution.
Steps to reproduce
Add a feature with a step to create content, the option index immediately on the configuration of search_api should be checked. and add the tag @search_api to execute the search_api behat step.
The tag will be ignored, and the content should not be indexed.
Proposed resolution
Refactor the code to use the tag @search_api.
| Comment | File | Size | Author |
|---|---|---|---|
| #10 | 3263875-10--fix_behat_integration.patch | 1.78 KB | drunken monkey |
Issue fork search_api-3263875
Show commands
Start within a Git clone of the project using the version control instructions.
Or, if you do not have SSH keys set up on git.drupalcode.org:
Comments
Comment #2
eduardo morales albertiComment #3
eduardo morales albertiComment #5
eduardo morales albertiComment #6
eduardo morales albertiComment #7
eduardo morales albertiComment #8
drunken monkeyThanks for reporting this issue!
However, as I don’t use Behat, I have no idea whether this is really a problem or whether your solution makes sense. I’ll therefore have to wait until someone else confirms both the existence of the problem and that your MR resolves it.
(Also, please don’t use MRs in this project, as testing for them doesn’t work. Use a patch instead.)
Comment #9
GrumpySchlagHi,
First of all, I can confirm that the changes integrated following the https://www.drupal.org/project/search_api/issues/3115214 issue and integrating the @search_api tag never worked for me.
I came across this issue and the fork made by Eduardo Morales Alberti and tried the code he proposed on my project and it works.
Needing a patch for this update and having seen drunken monkey's comment, I took the liberty of making a patch from the fork.
This one works well for me. (Tested on a project on Drupal 9.4.15 & PHP 7.4)
Being new in the world of contribution, I hope I did things correctly and thank you in advance for your answers.
Have a nice day
Comment #10
drunken monkeyWelcome to the world of contribution, GrumpySchlag! And thanks for reporting back that this is indeed a problem, and fixed by the proposed changes.
Your patch is almost perfect, we just use indents of two spaces in Drupal, not four.
Also, going over the patch I noticed a few suboptimal bits about the original MR. Please test/review the attached patch and tell me if it still works correctly for you, then I can commit.
In any case, thanks again!
Comment #11
GrumpySchlagHi again,
I tried your patch and it still work for me.
Thanks !
Comment #13
drunken monkeyGood to hear, thanks for reporting back!
Merged.
Thanks again, everyone!
Comment #14
drunken monkey