The background:
I'm working on content_permissions integration. When the anonymous user no longer has access to CCK fields, they don't get indexed in any way. Prior to the change in the indexing, CCK text fields would always get smooshed into the the $node->body at index time. Now we need a way to get these CCK fields into the index as their own field so that we can execute searches on them and respect the proper privileges. As it stands, we have the infrastructure for indexing CCK fields. The current limitation, however, is that we only do so for purposes of faceting. This means two things. First, we need a way to index CCK fields as text (so they can be searched on), and we need a way to say that we're NOT trying to facet on these fields.

My proposed solution adds a 'facets' key to the CCK field definitions array, which takes a TRUE or FALSE. This is used to determine whether facets should be built on that field. I then make it possible to have a 'default' CCK field definition for a field type, and for CCK text fields, I use the 'default' definition to index the field as text and mark it as as 'facets' = FALSE. This sets the stage perfectly for a new module to come along and do searches on these fields while respecting content_permissions perms.

Comments

robertdouglass’s picture

StatusFileSize
new6.25 KB

Talked to Peter, confirmed the approach. One change in this patch is that the actual 'default' definition for text fields won't come in the patch, but will rather be modified into $mappings in a module that you turn on specifically to ensure content_permissions compatibility. So that has been taken out of the patch. Everything else is essentially the same. Committing to 6.2. Marking to be ported for 6.1 consideration.

robertdouglass’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
Status: Needs review » Patch (to be ported)

#899590 by robertDouglass: Changed CCK facet definitions needs to expand its role and have a 'facets' param.

pwolanin’s picture

I don't see that this made it into 7.x either. This does seem pretty useful to have to avoid a confusing admin UI.

jpmckinney’s picture

Version: 6.x-1.x-dev » 7.x-1.x-dev
Status: Patch (to be ported) » Needs review
StatusFileSize
new2.81 KB
new2.37 KB
new653 bytes
new3.28 KB
new2.2 KB

Attaching a patch that ignores whitespace to make it easier to review.

We may have missed one in 6.x-2.x

pwolanin’s picture

Looking just at 6.x-1.x for the moment. Basically looks good, but possibly we want to make TRUE the default to make things nicer in terms of BC? At the least, we should either set a default or change this:

if ($field['facets']) {

to something like:

if (!empty($field['facets'])) {

to avoid notices about variables that are not set.

jpmckinney’s picture

+1 to !empty. To make "facet" => "TRUE" the default, wouldn't we have to instead make the key "nofacets" => FALSE? That way empty($field['nofacets']) will succeed on all existing fields.

pwolanin’s picture

Version: 7.x-1.x-dev » 6.x-1.x-dev
StatusFileSize
new3.88 KB

I meant we could set a default value. See attached.

jpmckinney’s picture

Yes, and I don't think that works. In 7.x, you simple don't set 'facets' if you don't want it. No 'facets' key is the same as 'facets' => FALSE.

With that patch, you must set 'facets' => FALSE, otherwise it defaults to TRUE, which is not what you expect. No 'facets' key becomes the same as 'facets' => TRUE.

I'd rather have the same behavior in both.

pwolanin’s picture

I think it's worth having different behavior in 6.x-1.x otherwise the upgrade will break people's custom cck mappings, so indeed that will have to specifically set 'facets' to FALSE.

We can make it default to TRUE in all branches (or flip the logic to 'nofacets') if you prefer consistency. I don't have a strong feeling as long as for 6.x-1.x an existing implementation would continue to work the same.

jpmckinney’s picture

Okay, let's go with setting a default in 6.x-1.x. We aren't trying to keep 6.x-1.x and 7.x in sync anyhow.

jpmckinney’s picture

StatusFileSize
new3.3 KB
new1.31 KB
new4.46 KB

For 6.1, do we need these lines from the 6.2 patch in #1:

+        if (!isset($mappings[$field_type][$widget_type]) && !isset($mappings['per_field'][$field_name]) && isset($mappings[$field_type]['default'])) {
+          $widget_type = 'default';
+        }

Brought 6.1 patch more in line with patch in #1 (without adding the above, though). Fixed 6.2 and 7.1 patches to use !empty.

elliotttf’s picture

Should the comments and readme file about cck field definitions be updated to include this field?

i.e.:

<?php
// A single default mapping for all text fields using optionwidgets.
$mappings['text'] = array(
  'optionwidgets_select' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
  'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
  'optionwidgets_onoff' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
);
// A single default mapping for all integer fields using optionwidgets.
$mappings['number_integer'] = array(
  'optionwidgets_select' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
  'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
  'optionwidgets_onoff' => array('callback' => '', 'index_type' => 'sint', 'facets' => TRUE),
);
// A field-specific mapping would look like:
// $mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string', 'facets' => TRUE);
// or
// $mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float', 'facets' => TRUE);
// Allow other modules to add or alter mappings.
drupal_alter('apachesolr_cck_fields', $mappings);
?>

and

hook_apachesolr_cck_fields_alter(&$mappings)

  Add or alter index mappings for CCK types.  The default mappings array handles just
  text fields with option widgets:

    $mappings['text'] = array(
      'optionwidgets_select' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE),
      'optionwidgets_buttons' => array('callback' => '', 'index_type' => 'string', 'facets' => TRUE)
    );

  In your _alter hook implementation you can add additional field types such as:

    $mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer');

  You can allso add a mapping for a specific field.  This will take precedence over any
  mapping for a general field type. A field-specific mapping would look like:

    $mappings['per-field']['field_model_name'] = array('callback' => '', 'index_type' => 'string', 'facets' => TRUE);

  or

    $mappings['per-field']['field_model_price'] = array('callback' => '', 'index_type' => 'float', 'facets' => TRUE);

  If a custom field needs to be searchable but does not need to be faceted you can change the 'facets'
  parameter to FALSE, like:

    $mappings['number_integer']['number'] = array('callback' => '', 'index_type' => 'integer', 'facets' => FALSE);

Other than that the patch looks good to me.

jpmckinney’s picture

Mind rolling a patch with those changes?

elliotttf’s picture

StatusFileSize
new5 KB
new3.19 KB
new5.55 KB

Done.

pwolanin’s picture

Status: Needs review » Reviewed & tested by the community

I haven't tested per-se but visual review looks like these are ready to commit.

pwolanin’s picture

Status: Reviewed & tested by the community » Fixed

committed all - though included another patch together with the 7.x one by accident.

jpmckinney’s picture

scor’s picture

Why was the drush command solr-phpclient removed with this commit?

jpmckinney’s picture

We no longer require you to download the phpclient.

pwolanin’s picture

@scor - see #16 - I committed 2 patches together by mistake.

Status: Fixed » Closed (fixed)

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