Hello,

CCK text fields are not indexed with nodes when running cron, when indexing all nodes.

How to index them?

If we have a text field into a indexed node with the value "Potatoes", we should find this node when we search the word "Potatoes", right?

There are a lot of CCK field available as filters but not text field. Why?

Comments

jpmckinney’s picture

Status: Active » Fixed

If the CCK field uses a text widget, then it can contain all kinds of values. So, it is not a good candidate for faceting.

If the CCK field uses a select widget, then it contains a fixed number of values. So, it is a good candidate for faceting.

We only index CCK fields if they are good candidates for faceting.

Now, for your problem: when you search for "Potatoes" with the apachesolr module, it looks for occurrences of "Potatoes" in the document's body field. This field contains the rendered node:

$node = node_build_content($node, FALSE, FALSE);
$node->body = drupal_render($node->content);

It also contains any content added by modules using the 'update index' case of hook_nodeapi.

So, if your CCK text field that contains "Potatoes" is not rendered with the node, then you should either implement hook_nodeapi or hook_apachesolr_update_index to add it to the document's body field.

Junro’s picture

Status: Fixed » Active

ok, sure cck text fields can't be use for faceting. I just want to index them.

then you should either implement hook_nodeapi or hook_apachesolr_update_index to add it to the document's body field.

Ok, but how to do it?

The code should be in apachesolr.index.inc. But I'm just a newbie in code and I don't really know what code I should write, and where to put it.

Thanks :)

jpmckinney’s picture

With hook_apachesolr_update_index you can do:

function MYMODULE_apachesolr_update_index(&$doc, $node) {
  $doc->body .= ' '. $node->field_MY_CCK_FIELD[0]['value'];
}

This may cause the CCK field content to appear in your search snippets, though.

Junro’s picture

Ok, so I put the code at the end of apachesolr.index.inc file:

function MYMODULE_apachesolr_update_index(&$doc, $node) {
  $doc->body .= ' '. $node->field_vegetables[0]['value'];
}

but MYMODULE, I must to replace it by what?

jpmckinney’s picture

You have to create a custom module and put it there: http://drupal.org/developing/modules

Junro’s picture

Thanks for your help, but I don't thing I'm able to create a custum module by myself :(

jpmckinney’s picture

Status: Active » Fixed
jpmckinney’s picture

pwolanin’s picture

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

This worked great for me...thanks. However, my results were showing img tags.
After a little digging, I realized I need to use 'view' instead of 'value' to recognize the display formats (in search tab) that I set for this field.

function MYMODULE_apachesolr_update_index(&$doc, $node) {
  $doc->body .= ' '. $node->field_MY_CCK_FIELD[0]['view'];
}