Currently, if you have a node index, you cannot change the "bundles" setting after the index has been created. The description simply states that "This setting cannot be changed for existing indexes." and the checkboxes are disabled. Is there a specific reason that this setting can't be changed after the fact?
In my case, I have my index hooked up to an Apache Solr server. I manually removed the #disabled key from the form element, checked off a new bundle, and saved the index. After that, I queued all content for re-indexing and content of my new bundle started to show up in my search results.
Again, this was only for my Solr setup, so maybe changing this afterwards causes other problems on different setups? If not, though, can we simply remove the #disabled key and add a warning to the description stating that you may need to re-index your items if you change the setting?
A patch is attached that would accomplish this.
Comment | File | Size | Author |
---|---|---|---|
#25 | 2632880-25--change_bundles_on_disabled_index.patch | 1.17 KB | drunken monkey |
| |||
#23 | 2632880-23--allow_changing_bundles.patch | 2.23 KB | drunken monkey |
Comments
Comment #2
Scott Robertson CreditAttribution: Scott Robertson commentedComment #3
ropic CreditAttribution: ropic commentedI tried the same but is not working for me, after adding new bundle and saving i cannot see any results on searches using views search.
Comment #4
geerlingguy CreditAttribution: geerlingguy commentedAttaching a quick reroll because for some reason the patch posted in the original issue is not working with drush make for me; I don't see any particular difference, though... just trying a rerolled patch.
Comment #5
geerlingguy CreditAttribution: geerlingguy commentedAh, it was because -dev and 7.x-1.16 have diverged and the patch in the OP doesn't apply to 1.16 :)
Carry on!
Comment #6
geerlingguy CreditAttribution: geerlingguy commentedHiding the patches that I uploaded; the latter of which will patch 7.x-1.16.
Comment #7
geerlingguy CreditAttribution: geerlingguy commentedBtw, I was working on an index where I wanted to add one more bundle, and using this patch and adding the bundle, then either queueing all content for reindexing, or dropping the index and reindexing still resulted in an index without that bundle present. Before I had 175 items in the index (there are 186 total nodes including the bundle that wasn't in the index), and after it still only indexed 175 items.
It looks like there might be something more to adding a bundle (or removing one).
Comment #8
geerlingguy CreditAttribution: geerlingguy commentedSo, it was just a matter of needing to do the following steps after applying the patch and changing the bundle settings:
drush sapi-dis [index_machine_name]
drush sapi-en [index_machine_name]
drush sapi-c [index_machine_name]
drush sapi-i [index_machine_name]
Simply clearing and reindexing (or queuing all content for reindexing) didn't work. I also had to disable/re-enable the index.
Comment #9
drunken monkeyYes, that's what I thought. I don't know why it worked for the OP, but from my understanding I think there's more to it. Internally, Search API has a table of all items for all indexes, and nodes of excluded bundles won't even be in there – re-indexing can't help you there.
You can see in the Drupal 8 version, though, that this is indeed possible, you just have to properly react to changes for existing indexes – i.e., find out which bundles got added or removed and then add/remove the entities from those bundles to/from the
search_api_item
table as appropriate. The only reason this wasn't done in Drupal 7 is because I didn't have enough time and this was still better than what we had before. But if someone provides a patch that properly implements this (optimally even with some tests), I'd gladly review and commit it.However, as it is, I don't think it's usable enough.
Comment #10
Scott Robertson CreditAttribution: Scott Robertson commented@drunken monkey, Yeah I wasn't so sure that it would work for a regular index. I'm guessing it worked alright for me because was indexing via Solr instead. If I have some time I'll try and see what needs to be done to make this more usable for all indexes.
Comment #11
ron_s CreditAttribution: ron_s commentedWe're running Solr, and I can confirm that we had to follow the steps described by @geerlingguy in #8.
Removing
#disabled
allowed us to add the bundle, but there were no results after reindexing. The only way we were able to see the new bundle in search results is by disabling/re-enabling the changed index, and then clearing and reindexing again.Comment #12
andileco CreditAttribution: andileco commentedThe steps outlined by @geerlingguy also worked for me. In addition to re-indexing, I also had to re-enable a search page that was disabled by disabling my index.
Comment #13
maximpodorov CreditAttribution: maximpodorov commented@drunken monkey, is it possible to accept the patch if it will contain the instruction of rebuilding the index properly?
Comment #14
drunken monkeyNo, that's not enough, sorry.
When manual rebuilding is required, you might as well just delete the index and create a new one with the correct settings.
Comment #15
maximpodorov CreditAttribution: maximpodorov commentedOh. It will require a ton of settings to be re-clicked.
Comment #16
ron_s CreditAttribution: ron_s commentedI'd have to agree with @maximpodorov. We have hundreds of settings in the index. Deleting and creating a new one is not realistic. I'm very glad we were able to get #8 to work, even if it was a manual process.
Comment #17
drunken monkeyYou can do it programmatically:
Comment #18
maximpodorov CreditAttribution: maximpodorov commentedSo, this can be done upon submitting the form with index settings, if bundle set is modified, right? Will you accept such a patch? :)
Comment #19
drunken monkeyI'd be glad to review and commit such a patch, yes!
And as said, you can just look at the D8 version of the datasource (that code will be moved soon, though, and made a bit more complicated, so better use that version I linked to) for how to implement this.
Comment #20
DamienMcKennaHere's the D8 code, before it disappears:
Comment #21
DamienMcKennaSo it seems the logic would need to go in SearchApiEntityDataSourceController::configurationFormSubmit(), right?
Comment #22
DamienMcKennaSo, making some headway on it, but I'm not sure about the actions loop - the D8 code has references to several methods that don't exist in the D7 codebase.
Comment #23
drunken monkeyGood start, thanks! Please see my additional corrections. (Not sure about the
array_diff_key()
change, but I think the bundles should be in the values in this case, not in the keys. See the beginning of the method.)Still to do:
- Implement the special case of an empty selection (needs to be interpreted as "all"). We could also set the field to "required" and default to all, but that would mess up existing sites, so I don't want to do that.
- Implement
getBundleItemIds()
– should be easy, though, just base it on the code instartTrackingFallback()
. In D8, we also had to take the languages into account, but luckily we don't have that problem here. (Unlucky for people with multilingual sites, but way easier to maintain.)- Add a test to ensure this actually works as intended.
Comment #24
donquixote CreditAttribution: donquixote as a volunteer commentedWould the following help?
- Change the text to "This setting cannot be changed for enabled indexes."
- Make the checkboxes editable if the index is disabled.
This would force people to disable the index before they change these settings.
Comment #25
drunken monkeyOh, yes, that would be a great interim solution. Very easy to implement, and would still do the job. Not very well, of course, but still undoubtedly an improvement. Thanks a lot!
The attached patch would implement this, please verify it works for you and I can commit it!
Thanks again!
Comment #27
manu manuThanks @drunken monkey, tested the patch from #25 and it worked without any problems.
Comment #28
drunken monkeyGreat, thanks for testing!
Committed.
Leaving at "Needs work" for the other, better patch from #23.
Comment #30
ramadan35 CreditAttribution: ramadan35 commentedThanks @drunken monkey, tested the patch from #25 and it worked
Comment #31
Paul Lomax CreditAttribution: Paul Lomax commentedPosting this here as this is the main article that comes up when searching around this subject. It's also highly relevant. This will allow you to modify the datasource and re-index everything in one nice db update.
Comment #32
azinck CreditAttribution: azinck commentedA note here for D8 users: it's true that you can change the bundles that are indexed. However, if you deploy this change by importing the changed configuration to another environment then the records in the search_api_item table do not get correctly updated. I'm not yet sufficiently familiar with D8 to offer opinions as to the best way to solve this problem.