Problem/Motivation
I need to facet on fields that are semantically equal, but have different field names. There are cases where it isn't practical or possible to re-use fields. In those cases one can use the field_mappings_alter hook and define a name callback to normalize different field names into a common field name for the different fields that are actually semantically equal. This should cause the various Drupal fields to be indexed into one Solr field, thus making it possible to facet elegantly across fields.
However, this fails because the function that returns information about what node fields should be indexed only supports one instance of a given field name per entity type. In strict Drupal terms this isn't necessarily wrong, but can lead to surprising results when the Apachesolr module allows for the field_mappings_alter hook to change field indexing keys.
Proposed resolution
I've worked out a fix for this issue and I'm working on a patch soon to be submitted. The fix simply lets field names stack on top of each other, indexing all instances of a given field name instead of indexing only the last one added.
Remaining tasks
Review is needed. I don't think it should break other functionality, neither does it alter any part of the API.
User interface changes
N/A
API changes
N/A
Original report by remimikalsen
N/A
| Comment | File | Size | Author |
|---|---|---|---|
| #1 | apachesolr-shared_field_name-1611338-1.patch | 7.13 KB | remimikalsen |
| #1 | apachesolr-shared_field_name-1611338-WITHOUT_SPACEFIX.patch | 2.6 KB | remimikalsen |
Comments
Comment #1
remimikalsen commentedPatch as promised.
The two patches do the same thing, but one is more compact as it doesn't fix new spacing to account for added loops.
It's easier to read the patch without spaces, but the one with spaces is more correct.
R
Comment #2
nick_vhLet's see if this breaks any of our tests.
Thanks for all the hard work!
Comment #3
nick_vhWould you be able to show us two code snippets? A before and after (as in, something that would fail without the patch and something that would work with the patch)
Thanks!
Comment #4
remimikalsen commentedIt's hard to show an "after" snippet, because the result of the change is only visible in the effectively indexed Solr fields. However, I have this code I can show to enlighten the problem further.
The first piece of code is adapted from a custom module I developed that implements the field_mappings_alter hook. It basically takes semantically equal fields and translates them to a commonly named Solr field. An example usage would be where different fields only use and display a sub-set of a "common taxonomy" based on criteria we can't cover when re-using fields across content types.
Without the patch, only one of the two mapped fields are indexed, because of this line of code in apachesolr.module:
The field that is indexed depends on what field is processed last. Changing this line of code to:
will "stack" the different fields on top of each other; thus needing a "loop" to process the stacked $rows (3 places in the code).
Was this what you had in mind when asking for snippets?
R
Comment #5
nick_vhThat was exactly what I wanted to see. I am going to dive deeper in to this problem and hopefully report back with possible concerns.
If I understand correctly, this does not break any API function, it just fixes one right?
Comment #6
remimikalsen commentedYou understand correctly, no changes in the API have been done, nor should the change impact the API, and it only fixes this one issue.
R
Comment #7
nick_vhCommitted to D7. Welcome on the committers list!
Comment #8
pwolanin commentedWait, what happened to my comment? I think there is too much code duplication here.
Comment #9
pwolanin commentedoops, nevermind - confusing 2 issues.
Comment #10
remimikalsen commentedThanks Nick! I'll hopefully be using this module heavily in the time to come, so this might not be the last you hear from me. And if you don't, it just means everything works :)
R
Comment #11
nick_vhSo I guess I have that I hope not to hear from you? ;-)
Always welcome in the issue queue!
Comment #12
nick_vhCommitted to D6
Comment #13
David_Rothstein commentedFYI, this does seem to have been an API change, due to:
Example: #1838854: Current version of Apache Solr Field Collection doesn't work with current Apachesolr
Comment #14
nick_vhWell, given that the module was just in RC or even still in beta back then, I don't see any reason to add a compatibility again. Are you ok with that?
Comment #15
David_Rothstein commentedYup, fine with me. (I just tracked the change down to this issue and figured I'd mention it since the comments above specifically discussed whether or not this constituted an API change.)