Support for Drupal 7 is ending on 5 January 2025—it’s time to migrate to Drupal 10! Learn about the many benefits of Drupal 10 and find migration tools in our resource center.
When new profile is created, it doesn't store the profile id causing the db_update under the apachesolr_mark_entity to not work because entity_id/pid is not in the indexer table.
Comment | File | Size | Author |
---|---|---|---|
#5 | indexing-on-insert-not-working-1784296-5.patch | 3.24 KB | asgorobets |
#1 | indexing-on-insert-not-working-1784296-1.patch | 3.81 KB | asgorobets |
Comments
Comment #1
asgorobets CreditAttribution: asgorobets commentedThis is really a problem with the code:
The indexing works if you do a full reindex, and it's not working as expected on hook_entity_insert and hook_entity_update.
Apachesolr module provides a good way of thinking and a good API for other modules to implement.
I've found that in the code:
The author is trying to implement his own reindexing mechanism instead of using apachesolr default. It's not working since apachesolr_mark_entity will do a db_update for a $profile->pid that's not yet in DB.
In this case profile2_apachesolr_profile2_insert will do nothing useful:
You got it right, the apachesolr_mark_entity will mark an entity for reindexing. But an existing one. It's useful to use it when you're posting a comment on a node and want to reindex node instead. Like here:
It's not really needed to use apachesolr_mark_entity to reindex the updated entity itself because apachesolr module already have a mechanism of doing this:
Take a look at this:
In this case db_merge will not only update a table with new values, but can also insert values. There is also a apachesolr_entity_insert hook that's calling the
apachesolr_entity_update function. This will index all the entities that were inserted or updated.
For this thing to work properly you have to set some values in $entity_info to notify apachesolr_entity_should_index function that the entity should be indexed:
The author did set some changes in hook_entity_info_alter():
As you can see the $entity_info['profile2']['apachesolr']['bundles'][$bundle_name]['index'] is wrong according to $info['bundles'][$bundle]['apachesolr']['index'] from apachesolr_entity_should_index function. Probably the apachesolr module was changed and this thing worked before, but it looks like the issue was reported from version 1.2 and is pretty old.
I did a patch to fix this issue as well as clean-up the project from unnecessary functions mentioned above.
I would also like to contribute to the module since it's been a while since the module was updated. You can make a maintainer if you feel that you don't have too much time for the project.
Thank You,
Alexei.
Comment #2
asgorobets CreditAttribution: asgorobets commentedComment #4
pwaterz CreditAttribution: pwaterz commentedLet me get this tested and will update it
Comment #5
asgorobets CreditAttribution: asgorobets commentedHi, I've improved a little bit the patch to avoid some notices and to use proper apachesolr API hook for updating entity_info.
In case the patch will not apply it's because of different line endings, you can use:
git am --ignore-space-change indexing-on-insert-not-working-1784296-5.patch
Comment #7
Ingmar CreditAttribution: Ingmar commentedPlease try to get this working. I could use this definitely!
Thanks for your effort!
Comment #8
pwaterz CreditAttribution: pwaterz commented@ingmar, why dont you try and patch and test it your self :)
Comment #9
pwaterz CreditAttribution: pwaterz commented@asgobets
why did you do this?
-function profile2_apachesolr_entity_info_alter(&$entity_info) {
- $entity_info['profile2']['apachesolr']['indexable'] = TRUE;
- $entity_info['profile2']['apachesolr']['status callback'][] = 'profile2_apachesolr_profile2_status_callback';
- $entity_info['profile2']['apachesolr']['document callback'][] = 'profile2_apachesolr_solr_document_profile2';
- $entity_info['profile2']['apachesolr']['reindex callback'] = 'profile2_apachesolr_solr_reindex_profile2';
- $entity_info['profile2']['apachesolr']['index_table'] = 'apachesolr_index_entities_profile2';
+function profile2_apachesolr_apachesolr_entity_info_alter(&$entity_info) {
+ $entity_info['profile2']['indexable'] = TRUE;
+ $entity_info['profile2']['status callback'][] = 'profile2_apachesolr_profile2_status_callback';
+ $entity_info['profile2']['document callback'][] = 'profile2_apachesolr_solr_document_profile2';
+ $entity_info['profile2']['reindex callback'] = 'profile2_apachesolr_solr_reindex_profile2';
+ $entity_info['profile2']['index_table'] = 'apachesolr_index_entities_profile2';
+}
I dont think that is right.
Comment #10
pwaterz CreditAttribution: pwaterz commentedAhh i see now, you are correct.
Comment #11
pwaterz CreditAttribution: pwaterz commentedI tried to apply the patch and it failed.
error: patch failed: profile2_apachesolr.module:1
error: profile2_apachesolr.module: patch does not apply
Comment #12
asgorobets CreditAttribution: asgorobets commentedI see, there's an issue with line endings, your files in repository have CRLF line endings and the patch is LF line endings.
Using git am --ignore-space-change indexing-on-insert-not-working-1784296-5.patch works for me. Did you tried that?
There are some issues describing the problem that you will want to take a look at:
Provide Git core.*crlf settings recommendations based on OS sniffing
CRLF line endings cause problems with "git apply"
Maybe the files should be converted to LF for convenience.
Comment #13
pwaterz CreditAttribution: pwaterz commentedInteresting, I use eclipse for development. I'll see if I can fix that.
Comment #14
pwaterz CreditAttribution: pwaterz commentedI added a dev branch release, and committed this patch there.
Comment #15
asgorobets CreditAttribution: asgorobets commentedThanks pwaterz!
Comment #16
pwaterz CreditAttribution: pwaterz commentedIn release 7.x-1.6