First off everyone, thank you for all your hard work on this integration. It truly is an incredible module.

I'm new, and barely do more then configuring drupal installs, but now may be the time I need to reach beyond the UI and play with code.

I'm only trying to index a single content type. It has a few fields, but strangely apache doesn't index the ones I need. They inclue "text" and "long text" fields. One is called

field_accommodations - it's a 'long text'

another is called

field_description - it's a 'text'

now per the instructions here : http://drupal.org/node/816428

I generated this and saved it as my custom.module

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

(question- how could I have re-written this code to also include my field_description?)

This should add it to index correct? So I upload the file. Run Cron. Check /admin/reports/apachesolr to see if it was indexed, and still no luck.

Any ideas?

Comments

Georgique’s picture

You should implement hook_apachesolr_index_document_build($document, $node, $namespace) to add some fields to your index:

function mymodule_apachesolr_index_document_build($document, $node, $namespace) {
  // First, you shoul write here $document variable to file to check if your field were indexed. If not, do this:
  if (isset($node->field_accommodations)) $document->addField('ts_field_accomodations', $node->field_accommodations[0]['value']);
  if (isset($node->field_field_description)) $document->addField('ts_field_description', $node->field_field_description[0]['value']);
}

You do not need to add this fields to body, just add them as fields.

Georgique’s picture

Field name standards:
xy_fieldname, where x - field type (s for string, t for processed text, i for long and f for float), y - single/multiple (s or m).

pwolanin’s picture

The code you wrote above should never need to be hand-coded. Make sure those fields are rendered as part of the body for the "search index" display in the field API UI.

Alternatively, if you want to be able to search fields individually and you are using field API fields you can implement hook_apachesolr_field_mappings and set a per-field mapping for those text fields.

stopshinal’s picture

The code you wrote above should never need to be hand-coded. Make sure those fields are rendered as part of the body for the "search index" display in the field API UI.

I agree, I was stumped to think I needed to go down this road. How can I go about verifying this? Or adding them?

Georgique’s picture

@pwolanin I also asked about indexing custom fields here: http://drupal.org/node/1504530
Now I tried both cases: hook_apachesolr_field_mapping and hook_apachesolr_index_document_build. As result I see that fields are in my $document, but when I perform search, it seems that solr does not searching in those fields. Is it searching only in 'content' field?

pwolanin’s picture

@Georgique - you'd need to modify the query to add them to the 'qf' param.

@stopshindal - look at the display mode settings, reindex after changing them.

Georgique’s picture

@pwolanin Can you give me small example how to add field to 'qf' param?

Georgique’s picture

@pwolanin I did it myself, thanks for support =)

function inti_apachesolr_query_alter($query) {
  $params['qf']['sm_author'] = 'sm_author^20.0';
  $params['qf']['sm_organization'] = 'sm_organization^20.0';
  $params['qf']['tm_field_author_org'] = 'tm_field_author_org^25.0';
  $query->addParams($params);
}
pwolanin’s picture

Status: Active » Fixed

Status: Fixed » Closed (fixed)

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

daniel.nitsche’s picture

Does this apply to excluding fields from the index as well? After removing a field from the "search index" view mode, then deleting the index and reindexing, I still see hidden fields in the index.

The only other way I can think of doing is to use hook_apachesolr_index_document_build, then unsetting the values or something, but I'm not sure if that's the best way to go?