Spoke with pwolanin in irc on how to go about excluding cck fields from the index. Was informed that excluding them from the NODE_BUILD_SEARCH_INDEX build mode in the cck field display settings will take care of this. Everything worked fine, however, after excluding the various fields and visiting the `Enabled Filters` tab (admin/settings/apachesolr/enabled-filters) all cck fields were present regardless of their exclusion setting for the search_index build mode.

After some poking around, i found that the list is populated without consideration of whether or not the field is included or excluded in the index. Here's a quick fix (i'm not so good with the whole patch thing yet so bear with me):

apachesolr.module apachesolr_cck_fields() function i made the following change that respects the exclusion setting for each field.

     ...
     // Allow other modules to add or alter mappings.
      drupal_alter('apachesolr_cck_fields', $mappings);

      $result = db_query("SELECT  i.field_name, f.multiple, f.type AS field_type, i.widget_type, i.label, i.type_name AS content_type, i.display_settings FROM {content_node_field_instance} i INNER JOIN {content_node_field} f ON i.field_name = f.field_name;");
      while ($row = db_fetch_object($result)) {
        // unserialize the display settings so fields can be excluded correctly
        $row->display_settings = unserialize($row->display_settings);        
        // Only deal with fields that have option widgets (facets don't make sense otherwise), fields that have been marked for exclusion,
        // or fields that have specific mappings.
        if ((isset($mappings[$row->field_type][$row->widget_type]) ||  isset($mappings['per-field'][$row->field_name])) && !$row->display_settings[NODE_BUILD_SEARCH_INDEX]['exclude']) {
          if (isset($mappings['per-field'][$row->field_name])) {
        ...

Comments

camidoo’s picture

oh, noticed that the comment should read:

// Only deal with fields that have option widgets (facets don't make sense otherwise), fields that have NOT been marked for exclusion,

instead of

// Only deal with fields that have option widgets (facets don't make sense otherwise), fields that have been marked for exclusion,
jpmckinney’s picture

Status: Active » Needs work
jpmckinney’s picture

Title: CCK Field Exclusion » Respect NODE_BUILD_SEARCH_INDEX exclusion setting
Status: Needs work » Needs review
StatusFileSize
new2.17 KB

For this patch to apply to 6.x-1.x, #551278: CCK mappings don't respect shared fields will have to be ported first.

Just want a sanity check before committing this as I'm less familiar with the CCK integration part of the module.

camidoo’s picture

i'll take a look at this shortly

rjbrown99’s picture

StatusFileSize
new2.76 KB

Enclosed is the patch from #3, ported to the current DRUPAL-6--1 tree as of this morning, and also including the patch from #551278: CCK mappings don't respect shared fields. Again this is for the 6.x-1.x-dev branch, not the 2.x branch.

I'll be testing later and will report back.

pwolanin’s picture

Let's go for a combined patch here for 6.x-1.x - so marking #551278: CCK mappings don't respect shared fields closed.

Are we sure that $row->display_settings[NODE_BUILD_SEARCH_INDEX]['exclude'] is always set?

pwolanin’s picture

StatusFileSize
new2.48 KB

Here's a combined 6.x-1.x patch. Quick test looks good.

pwolanin’s picture

Looks at the code - we are in a bit worse shape than I thought.

Working on a patch to use the CCK API rather than do direct table queries.

Also, we don't flag nodes for re-indexing if the 'exclude' setting is changed for one of its CCK fields - seems like that's something we should do?

pwolanin’s picture

StatusFileSize
new5.68 KB

Adds an implementations of hook_content_fieldapi()

pwolanin’s picture

Version: 6.x-2.x-dev » 6.x-1.x-dev
janusman’s picture

Just a quick review...

+++ apachesolr_search.module
@@ -532,7 +532,7 @@ function apachesolr_search_apachesolr_facets() {
-        'info' => t('Apache Solr Search: Filter by @field', array('@field' => $field['label'])),
+        'info' => t('Apache Solr Search: Filter by @field', array('@field' => $field['widget']['label'])),

This seems like an extra fix, but doesn't seem to hurt =)

Otherwise, code looks fine.

jpmckinney’s picture

Looks sane (though, I'm not super familiar with the CCK API). Do we not need to load module_load_include('inc', 'content', 'includes/content.crud'); in the hook_content_fieldapi?

pwolanin’s picture

re: #11 - since we are taking the data from cck instead of buiding it ourselves, the array keys change in a few palces such as that.

re: #12, that hook is invoked from content.crud.inc, so it will always be loaded afaik.

pwolanin’s picture

StatusFileSize
new6.53 KB

putting back in James' change to !isset() from is_null()

pwolanin’s picture

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

committed to 6.x-1.x, patch needs to be ported since there are conflicts in 6.x-2.x

"#751004 by jpmckinney, camidoo, rjbrown99, pwolanin: fix use of CCK API, handle NODE_BUILD_SEARCH_INDEX exclusion setting in the UI."

pwolanin’s picture

Hmm, interesting possible side-effect - if you are using taxonomy based node access, the terms not accessible to anonymous uers will not get indexed http://api.drupal.org/api/function/taxonomy_node_get_terms/6

This is basically the desired behavior (it leads to consistency) - but leads more urgency, perhaps, to the option of being able to index content as user X.

eugenmayer’s picture

Status: Patch (to be ported) » Needs review

Well actually, why do we index as anon? This is a administration task, or do i miss something?

So we want all fields not excluded somehow ( not by permissions but the hooks ) going into the index. When users search, we respect permissions. Thats exactly the way to go. Using anons you probably fetch half of the data, because anon cant access some fields / taxonomies and more. The searching user then could access those fields but cant search for them.

Indexing must always be done with uid=1 or "administer content" permissions and that should eb checked beforehand and told to the user, that he must switch permissions.

Anon indexing might work for "public only" sites. But it wont work for private sites or mixed. And as apachesolr already supports nodeaccess it does not make any sense removing that support here.

After removing anon indexing my taxomomy indexing worked fine again

pwolanin’s picture

Status: Needs review » Patch (to be ported)

@EugenMayer - most sites run cron as the anonymous user and hence index content that way in Drupal core search.

This change brings consistency - we always know the content is indexed as user 0. This is also the only way we can avoid information disclosure without a more complex scheme as described above. A secheme which will have to be implemented by another module

eugenmayer’s picture

You mean most sites which dont have any permissions? Is that an argument? And no, taxonomy indexing with an anon user makes absolutely no sence. Did you ever thought about taxonomy_access?

pwolanin’s picture

@EugeMayer - yes, I did think about it. The discussion above about CCK fields applies equally to taxonomy.

I also discussed the issue quote a bit with jhodgdon in IRC. Basically - there is no easy of totally satisfying solution. The approach of only indexing (by default) content available to anonymous users is the safest in terms of minimizing the likelihood of information disclosure.

Look at the README here: http://drupalcode.org/viewvc/drupal/contributions/modules/search_by_page...

That module offers a more graduated control by indexing search content as a user with a specific role, but has to jump through hoops like creating fake user accounts. This is not something I'm especially interested in maintaining, but I be happy to consider your patch to add a simplified version of the functionality (e.g. being able to specify a user that is user when indexing content).

eugenmayer’s picture

Well i cant even thin about why creating fake users.

uring index-time _all_ fields which are _not_ excluded _site wide_ (or not added to the index in the solr config) should be indexed.
Why?: Because if it is hidden by a permission there are users on the page being able to access those fields and they _cannot_ searc for it anymore neither use it as facet. This just makes the whole solr aproach useless.

If you dont like a field to be index:
- Exclude it using the api
- Dont add it in the CCK options in solr
- dont add the taxonomy facet in solr ( for that taxonomy)

This issue def. deals with the wrong problem and thats misconfiguration OR bad access implementations. e.g. i implemented by own version of "apachesolr_access" to respect the rights i have in my Drupal installation. Because everthing should be indexed, but not everthing should be included in the search result. Thats very much possible for cck fields or other things also - but you _have to index them_.

If this patch goes thtough and you talk about "consitency" i ask myself, why apachesolr_nodeaccess ever got implemented. Its against this approach in any way it has been done.

"filter on query" rather then "never index".

To be more clear, iam not for "use the current user for indexing". Iam for use the full-priv user with all rights ( administer content ), so rather uid=1.

Anyway i would be glad if you could add an option to disable anon indexing.

pwolanin’s picture

@EugenMayer - patch?

eugenmayer’s picture

I open a new issue for that when i find time for the implementation and provide the patch.

robertdouglass’s picture

Status: Patch (to be ported) » Needs review
StatusFileSize
new9.23 KB

Here's a 6.2 version.

pwolanin’s picture

Note that Drupal 7 core now always runs cron as user 0 with very similar code, so I think it's far to say we are making a reasonable choice, and also we shoulf not need to port this change to Drupal 7.

http://api.drupal.org/api/function/drupal_cron_run/7

robertdouglass’s picture

Status: Needs review » Fixed

#751004 by pwolanin, jpmckinney, rjbrown99, robertDouglass | EugenMayer, camidoo: Fixed Respect NODE_BUILD_SEARCH_INDEX exclusion setting.

Status: Fixed » Closed (fixed)

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

eugenmayer’s picture

Status: Closed (fixed) » Active

Sorry for reopening this one.

Looking at the patch ( pretty huge ) iam not sure what is implemented now. The patch seems to include some quiet other changes also.

What user is used for indexing now? Can i configure this?

jpmckinney’s picture

@EugenMayer As mentioned earlier, please open a new issue if you want to be able to index as a different user.

Re: #8 "Also, we don't flag nodes for re-indexing if the 'exclude' setting is changed for one of its CCK fields - seems like that's something we should do?"

For 7.x, do we need to implement hook_content_fieldapi as hook_field_update_instance to accomplish the same thing?

jpmckinney’s picture

Version: 6.x-2.x-dev » 7.x-1.x-dev
jpmckinney’s picture

Title: Respect NODE_BUILD_SEARCH_INDEX exclusion setting » Flag node for re-indexing if the 'exclude' setting is changed for one of its fields
nick_vh’s picture

Status: Active » Closed (won't fix)

From above :

and also we should not need to port this change to Drupal 7.

Marking this as closed, won't fix. I assume this kind of behavior is already available in Drupal 7 branch. If not, please reopen or state clearly what should happen?