The docblock for Index::addField() implies the method can, under certain circumstances, update an existing field. This functionality was removed at https://cgit.drupalcode.org/search_api/diff/src/Entity/Index.php?id=69cf213 (see diff around line 565, etc.)

I would like to be able to update fields, however it looks like this change was purposeful and I'm not familiar enough with the internals to submit a patch to add a method, so this is just a quickie to at least update the docblock so others don't rely on this capability like I did, only to get an Exception later.

Thanks for all the great work on search api and I hope I can help more in the future.

CommentFileSizeAuthor
search_api_add_field.patch1.11 KBbradjones1

Comments

bradjones1 created an issue. See original summary.

borisson_’s picture

Status: Needs review » Reviewed & tested by the community

Awesome! Documentation updates are great. Thank you!

drunken monkey’s picture

Status: Reviewed & tested by the community » Fixed

I agree, thanks a lot!
Committed.

And you're right, this was done on purpose. Now you either need to first remove the existing field (if you want a completely new definition) or just get the current field and change its settings as appropriate. E.g., like we do in BackendTestBase:

$index->getField('body')->setType('string');
$index->save();

If you have an idea how to better document this, please go ahead and propose it (or add it to our online documentation).

Status: Fixed » Closed (fixed)

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