Hi,

I spent about 5 hours looking for a solution to make CCK field content searchable. The only thing I found was to put all field in the body field.
Is there a better way to include CCK field in a search? I read in some discussion a suggestion to give all CCK field a checkbox whether to include that field in the search.

Can someone shine some light on this please?

Thanks in advance
Jan

Comments

regx’s picture

The CCK Field Permissions module seems to allow searching cck fields / sub fields. Unfortunately, private fields are also indexed. Private fields do not show up in the search results if the user doesn't have permission to see them, but the nodes with matching fields do show up.

yched’s picture

Status: Active » Fixed

I do not get what the initial post is about. CCK fields do get indexed.
The problem is rather that too much gets indexed : field labels are indexed as well, which you generally don't want.

Unfortunately, this is a core issue - when the node is rendered for indexing, CCK has no way to differentiate this from a regular 'full node' view, so you get the labels.

As for the 'CCK field perms' mentioned in #2, I'm afraid this just means that that the indexed fields are the ones the 'cron user' (anonymous, if I'm not mistaken) is allowed to see, which does not completely makes the trick.

What we actually need here is a 'search index' rendering style - see eaton's http://www.drupal.org/node/144608 and http://www.lullabot.com/blog/trouble_nodes

Anonymous’s picture

Status: Fixed » Closed (fixed)
haraldessert’s picture

Assigned: Unassigned » haraldessert
Status: Closed (fixed) » Postponed (maintainer needs more info)

I don't think this is fixed!!

I made a CCK field to fill just with words related with the node, that not necessarily are contained in the body field.
In 'Display fields' I set this key-word text field to be hidden, since I didn't want it to show up in the node. I wanted this field just to be indexed in the search results.

BUT IT DOESN'T !!!

-------------------------------
For example:
I created an image node, containing the picture of a stone. The body explains about the picture, the kind of stone, etc. And in my 'key-word' field I put related words that don't appear in the body, but could be helpful for someone to search pictures in my site, like: rock, stoney, hard, etc.

But when I search the word 'rock', that is not mentioned in the body, but just in the hidden cck text field, there are no results.
-------------------------------

So I guess we STILL HAVE an issue here. And I think this is really important.

Maybe, not just text fields should appear in the search results, but also image fields!! (That'd be awsome!!)

Has anyone already solved this?

drewschmaltz’s picture

did you run cron? how much of your site is indexed. I'm pretty sure everything you want to happen - happens.

haraldessert’s picture

Yes!! I've already tried to run cron.
And 100% of the site is indexed.

But there are still no results!! I've also tried to make the field visible again (just for the try) and then run cron. But there was nothing different.

Still trying, here.

If you wish to try, the site is here:
www.kphotos.com.br/photo
It's still in development.

For example, the node called Zoom numa pedra has a description containing just the word stone (cause it's a picture of a stone), and I put the word 'rocha' (rock, in portuguese) within the keywords to make it easier to find it, even with other words.

Give it a try, and you'll see, that it doesn't return any results.

I just can't see why :S

Moonshine’s picture

The word "rock" or "rocha" doesn't seem to appear anywhere in the node output on that page that I can see. So I really doubt it would make it into the index if it doesn't appear on the node. Assuming you put it into some "description" field, make sure that field is rendered in some way on the node, then reindex and try searching.

NoRandom’s picture

I'm having the same problem.

In my case I've added a "credits" field for each "game" node type. I render this field in my custom template using:

print content_format('field_credits', $field_credits[0], 'default' )

The site is fully indexed. And when I make a search I never get data from "credits" fields.

You can check it here: http://www.pixelgordo.com/juego/full-throttle

At the top, if you click on "mostrar crédidos" you can see the field properly rendered (it's shown/hidden by jquery). But if you search for "Tim Schafer" you won't get any result. Help picture here: http://img397.imageshack.us/my.php?image=capturacy9.png

I'm using a plain cck installation without any extra fields from other projects.

haraldessert’s picture

The word 'rocha' is really in no output of my node, beacuse I hid it in the 'Display fields' settings.
It is in my 'key-word' text field, that shouldn't really appear anywhere, except in the search results.

The 'description' text field appears on the left-sidebar when you open a picture, right under the node title. So it IS rendered. But it still doesn't appear in the search results.

But I thought of something: I also hid this 'description' field, like I did with my 'key-word' field, in the 'Display fields', beause I didn't want it to be shown in the node. But I recall it using the command:

<?php
print $node->field_descricao[0]['value'];
?>

within my page.tpl.php file.
So I could display it somewhere else on my page, without beeing IN the node output. I think it just doesn't appear in the results because it is hidden!!

So I tried making it visible, and then I re-indexed the site and BADABIN-BADABUM, there it appeared in the results.

Now I guess the only way I have it not to be shown in the node display (just in my left-sidebar) and still show it in the search results is making it with visibility:hidden in the CSS file.

It's kinda dirty... But what else is left??

haraldessert’s picture

I think we can leave this explanation text here on the end, if anyone agrees:

1) CCK fields that are set as hidden in the 'Display fields' configurations DON'T appear in the search results, even if you render it somewhere else on your custom page. You can re-index your site and it just won't appear.

2) Although you don't want this field to appear in your node display, if you need it to be shown in the search results you'll have to make it visible in the 'Display fields' settings and hide it somehow else.

Not even drupal is perfect!! =D
But we just love it, don't we??

Thx, folks!!

NoRandom’s picture

Yes, it works ;). It's not the perfect solution but it's a good workaround.

Kind regards and thanks a lot for your help.

haraldessert’s picture

Status: Postponed (maintainer needs more info) » Fixed

Really not the perfect solution!! ;)
Maybe anyone has another answer, more soffisticated!!

Y que sitio hermoso el tuyo, Macarro!! Avisanos cuando está listo!!

Moonshine’s picture

Well if you want some good information on how search indexing works in Drupal check out:

http://acquia.com/blog/drupal-search-how-indexing-works

NoRandom’s picture

Muchas gracias, haraldessert ;)

Thanks a lot. I'm working on it at spare time and for a mix between fun and learning. I need to add some new content types with their little customized templates and finally build the relations between them. I'll post my progress here: http://drupal.org/node/295359

Anonymous’s picture

Status: Fixed » Closed (fixed)

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

haraldessert’s picture

Thanks for that, Moonshine!!

Taking a look at that post about Drupal Search.

mchaplin’s picture

Version: 5.x-1.4 » 6.x-2.0-rc7
Component: General » Usability
Assigned: haraldessert » mchaplin

It took me a while to figure out how to get the Search to find data in CCK fields. I'm using Drupal 6.9.

1) The relevant content_permissions module "view field_mycckfield" must be checked ON for the anonymous role. I think this is because the indexing is done via an anonymous user in cron. Once ON, you need to re-index in "Search settings" and wait for the next cron to complete. This can take some time depending on the size of your site.

2 Red herrings:

2) The CCK Field Indexer module is NOT required which at first seems counter intuitive given its module description: "Allows the indexing of CCK fields into the search index." Its purpose is described more fully at http://drupal.org/project/field_indexer.

3) The Display fields | Advanced settings for the relevant CCK data type can be used exclude fields from the search index and/or search results. However I found that the initial "Default" setting allowed the indexing and display of CCK fields.

Hope this helps someone else if they're struggling with this.

anrikun’s picture

Title: Searching on CCK fields » Searching on CCK fields: a quick fix
Version: 6.x-2.0-rc7 » 6.x-2.4
Component: Usability » content.module
Status: Closed (fixed) » Needs review
markus_petrux’s picture

Title: Searching on CCK fields: a quick fix » Searching on CCK fields
Version: 6.x-2.4 » 6.x-2.0-rc7
Component: content.module » Usability
Status: Needs review » Closed (fixed)

@anrikun: This issue was closed. CCK supports indexing of fields which can be configured from the "Display fields" panel.

If you need advice or wants to provide a fix for something, the please open a separate issue and explain as much as you can what are you trying to point out. Thanks

anrikun’s picture

Title: Searching on CCK fields » Content Permission: Searching on CCK fields not accessible to anonymous users doesn't work
Version: 6.x-2.0-rc7 » 6.x-2.4
Component: Usability » Content Permissions module
Assigned: mchaplin » anrikun
Category: support » bug
Status: Closed (fixed) » Needs review

Yes CCK supports indexing of fields but ONLY if they are accessible to anonymous users.
That means that if you enable Content permission and set a field as not viewable by anonymous users (for instance, to restrict access to this field to privileged users), this field won't be indexed at all, and privileged users won't be able to search on it.

This is because of line 768 in content.module (6.X-2.4):

          '#access' => $formatter_name != 'hidden' && content_access('view', $field),

which should be replaced by:

          '#access' => ($formatter_name != 'hidden') && (($context == NODE_BUILD_SEARCH_INDEX) || content_access('view', $field)),

As a matter of fact, when a scheduled cron is run, it is run as an anonymous user, so without the fix above, fields not accessible to anonymous users are not indexed.
But if you reset indexing and run the cron manually, from admin pages, the original code above will work and fields will be indexed (because admin user can access everything).
So as for me this is a bug: it works in a case and not in another.

The fix above works for me, and I would appreciate if it could be reviewed by community.
And if someone could make a patch...

markus_petrux’s picture

Title: Content Permission: Searching on CCK fields not accessible to anonymous users doesn't work » Searching on CCK fields
Version: 6.x-2.4 » 6.x-2.0-rc7
Component: Content Permissions module » Usability
Assigned: anrikun » Unassigned
Category: bug » support
Status: Needs review » Closed (fixed)

Re: "Yes CCK supports indexing of fields"

Sure, and this was the purpose of this issue. But, since you're describing a related but different thing, then please open a separate issue. When doing do, please describe it, don't simply post a link to a forum topic. Also, don't assign an issue to yourself if you don't plan to work on it, where that means providing patches, etc. Thanks

Reverting the status of the issue to where it was.

That being said, a problem with your proposed solution is then that anonymous user will get matches for text they cannot see. And I suspect that's the reason why it is like it is. But this could be better discussed on a separate issue, because the original request here was resolved.

anrikun’s picture

OK, new issue is here:
http://drupal.org/node/510744