This module provides a data alteration callback for Search API very similar to 'Aggregate Fields', but instead of reducing fields values into a single value, it keeps fields values "as is" so they are indexed into multi-valued indexes.

Drupal version: 7
Required modules: Search API
Sandbox project: http://drupal.org/sandbox/jajm/1870400
Git repository: git clone --recursive --branch 7.x-1.x http://git.drupal.org/sandbox/jajm/1870400.git search_api_multi_aggregate

Why you need it?

This module is useful when you want to aggregate fields and index the new field as string (for faceting for example).

Example

You have 2 fields:

  • Primary authors which contains the following values
    • "Primary 1"
    • "Primary 2"
  • Secondary authors which contains the following values
    • "Secondary 1"
    • "Secondary 2"

and you want them both to be used in one single Facet block.
You have to create a new field that will contains values of both these fields.
You can use the 'Aggregate Fields' that comes with Search API module for that. But there is a small inconvenient:

  • If you index the new field as "Fulltext", your facets will looks like
    • "Primary"
    • "Secondary"
    • "1"
    • "2"
  • If you index the new field as "String", you will get only one facet:
    • "Primary 1 Primary 2 Secondary 1 Secondary 2"

Using Search API Multi Aggregate will allow you to have the facets you want:

  • "Primary 1"
  • "Primary 2"
  • "Secondary 1"
  • "Secondary 2"

How to use it?

  1. Install and enable the module
  2. Go to your Search API Index configuration, under Workflow tab
  3. You should see a new type of data alteration: "Aggregated fields (multi-valued)". Enable it
  4. Under "callback settings", click on "Add new field" and configure it (fill its name and choose the fields to aggregate)
  5. You should now see a new field in the fields list. Check it and choose "String" type
  6. Re-index
CommentFileSizeAuthor
#1 coder_review.txt4.57 KBstrakkie
Support from Acquia helps fund testing for Drupal Acquia logo

Comments

strakkie’s picture

FileSize
4.57 KB

Hi Julian Maurice,

A few points, Coder gives a few errors:
search_api_multi_aggregate.module

Line 1: End of line character is invalid; expected "\n" but found "\r\n" [sniffer_generic_files_lineendings_invalideolchar]

severity: minorreview: sniffer_internal_lineendings_mixed
Line 1: File has mixed line endings; this may cause incorrect results [sniffer_internal_lineendings_mixed]

severity: minorreview: sniffer_whitespace_fileend_fileend
Line 26: Files must end in a single new line character [sniffer_whitespace_fileend_fileend]

callback_add_multi_aggregation.inc

Line 1: End of line character is invalid; expected "\n" but found "\r\n" [sniffer_generic_files_lineendings_invalideolchar]

severity: minorreview: sniffer_internal_lineendings_mixed
Line 1: File has mixed line endings; this may cause incorrect results [sniffer_internal_lineendings_mixed]


severity: minorreview: sniffer_whitespace_fileend_fileend
Line 247: Files must end in a single new line character [sniffer_whitespace_fileend_fileend]

With coder set to strict it finds more errors, try to fix these to (see attachment).
I think a lot of these errors are caused because of the line endings on your system (are you on a windows system?). I have had the same problem and used EOL conversion on my notepad++ to remove all errors about the docblocks.

Manual review,
code looks ok. I would add a few inline comments to the functions in callback_add_multi_aggregation.inc for readability.

Julian Maurice’s picture

Hi strakkie, and thank you for this first review.

I just installed Coder and ran the following command:

drush coder-review search_api_multi_aggregate

It didn't find any problems:

Drupal Coding Standards

sites/all/modules/search_api_multi_aggregate/search_api_multi_aggregate.module:
 No Problems Found

sites/all/modules/search_api_multi_aggregate/includes/callback_add_multi_aggregation.inc:
 No Problems Found

Coder found 1 projects, 2 files, 0 warnings were flagged to be       [status]
ignored

To be sure I checked with hexdump but found only line feed ('\n', 0x0a) characters and no carriage return ('\r', 0x0d) character.
Are you on a Windows system (I'm on a Linux system) ? How did you checkout the code? There is something strange here...

I checked my code with ventral.org too and found 2 more warnings (about README.txt and function naming). These warnings are now fixed on 7.x-1.x branch.

klausi’s picture

We are currently quite busy with all the project applications and I can only review projects with a review bonus. Please help me reviewing and I'll take a look at your project right away :-)

balsama’s picture

Status: Needs review » Needs work

I can confirm that the modules does not generate any errors or warnings when run through the coder module.

One small suggestion would be to reconsider consider the module name, or at least verify that all of the underscores don't introduce the possibility for namespace collisions.

I assume the concatenation going on in lines 14-16 of the .module are to stay under the 80 character limit. But I'm not sure that limit applies to code. Either way, that's a pretty clunky workaround and we should probably come up with a better solution.

Julian Maurice’s picture

Status: Needs work » Needs review

Hi balsama,

http://drupal.org/coding-standards#linelength says lines shouldn't exceed 80 characters excepted for « Lines containing longer function names, function/class definitions, variable declarations, etc » and « Control structure [...], if they are simple to read and understand »
It says nothing about long strings so I think these lines should be kept as is. I don't know how to make them prettier and I don't want to write lines of 200+ characters where it can be avoided.

About the module's name, if I change it, how I can be sure it won't collide with any other module's name?

Thanks.

balsama’s picture

Hi Julian,

Naming
The potential problem with the module name would be, for example, if there were a HOOK_aggregate function. In that case, the function search_api_multi_aggregate() becomes an implementation of HOOK_aggregate by a module named `search_api_multi`. I don't think there is an official position on this, so it shouldn't stop this from being RTBC, but it's worth thinking about. Here is the original article I read that made me think about it: http://drupalize.me/blog/201301/naming-things-hard

Line length
I'm certainly not in a position to override the documentation you referenced. But I would imagine that concatenating strings wasn't the original intention of that standard. A quick spot check reveals that MANY of core modules have lines of code WELL above 80 characters (check out line 50 of the core user.module file: 1,020 characters!) And it's my opinion that line breaking/concatenating actually makes the code less readable. I'd love to hear someone else chime in on this.

Julian Maurice’s picture

Naming
Ok, you convinced me. I removed underscores as suggested in http://drupalize.me/blog/201301/naming-things-hard

Line length
I don't want to fight for this, and if core modules contain very long lines, I suppose this is ok.

Branch 7.x-1.x updated.

PA robot’s picture

Status: Needs review » Closed (duplicate)
Multiple Applications
It appears that there have been multiple project applications opened under your username:

Project 1: http://drupal.org/node/1917088

Project 2: http://drupal.org/node/1844646

As successful completion of the project application process results in the applicant being granted the 'Create Full Projects' permission, there is no need to take multiple applications through the process. Once the first application has been successfully approved, then the applicant can promote other projects without review. Because of this, posting multiple applications is not necessary, and results in additional workload for reviewers ... which in turn results in longer wait times for everyone in the queue. With this in mind, your secondary applications have been marked as 'closed(duplicate)', with only one application left open (chosen at random).

If you prefer that we proceed through this review process with a different application than the one which was left open, then feel free to close the 'open' application as a duplicate, and re-open one of the project applications which had been closed.

I'm a robot and this is an automated message.

Julian Maurice’s picture

Status: Closed (duplicate) » Needs review
Julian Maurice’s picture

http://drupal.org/node/1844646 has been marked as "closed (duplicate)"

kscheirer’s picture

Status: Needs review » Reviewed & tested by the community

Your project page is way more informative than the README.txt file, you should improve that.

Module code looks good.

----
Top Shelf Modules - Enterprise modules from the community for the community.

Julian Maurice’s picture

Thank you for the review.
README.txt is now up-to-date.

http://drupalcode.org/sandbox/jajm/1870400.git/blob/HEAD:/README.txt

kscheirer’s picture

Title: Search API Multi Aggregate » [D7] Search API Multi Aggregate
Status: Reviewed & tested by the community » Fixed

Still looks good, and it's been over a month.

Thanks for your contribution, Julian Maurice!

I updated your account to let you promote this to a full project and also create new projects as either a sandbox or a "full" project.

Here are some recommended readings to help with excellent maintainership:

You can find lots more contributors chatting on IRC in #drupal-contribute. So, come hang out and get involved!

Thanks, also, for your patience with the review process. Anyone is welcome to participate in the review process. Please consider reviewing other projects that are pending review. I encourage you to learn more about that process and join the group of reviewers.

Thanks to the dedicated reviewer(s) as well.

----
Top Shelf Modules - Crafted, Curated, Contributed.

Status: Fixed » Closed (fixed)

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

Anonymous’s picture

Issue summary: View changes

added project links