Should be a methods to alter indexing. For example: I don`t want to create dynamic field "t_body:summary" for body summary coz I have custom field "body_summary" defined in schema.xml

Comments

d.olaresko’s picture

StatusFileSize
new2.26 KB

Patch that adds hook_search_api_solr_index_items_alter(). Also contains hook description

drunken monkey’s picture

Status: Active » Needs review
StatusFileSize
new1.31 KB

Why not just rename your custom field to "t_body:summary"?

Regardless, this would really be a useful addition to the module. However, I do think something like hook_search_api_solr_field_mapping_alter($index, &$fields) would be better. The hook you are proposing largely overlaps with hook_search_api_index_items_alter(), and couldn't really be called at search time. (OK, you could easily do it by providing an empty array, but there is really no point, in my opinion.) However, if you index your data in a different field, chances are pretty high you'll also want to search that field, not another, empty one. This can of course already be altered, but I think we could and should just include it in that hook.

How about the attached patch, would that also fit your requirements? Or would you say there is a use case for only altering field mappings when indexing, or only when searching? (We could do this just by using an additional $phase parameter, but the code just looks so good right now that I don't want to add this, unless necessary.)

d.olaresko’s picture

Why not just rename your custom field to "t_body:summary"?
Coz sometimes we have complicated fields (property_type "struct") or need to use body and custom fields... if I understood the question correctly.


How about the attached patch, would that also fit your requirements? Or would you say there is a use case for only altering field mappings when indexing, or only when searching? (We could do this just by using an additional $phase parameter, but the code just looks so good right now that I don't want to add this, unless necessary.)

In my case i`m altering field mapping when indexing and searching. Your patch looks great. I think this will be enough. Thx.

drunken monkey’s picture

Title: Add Solr-specific index alter hooks » Add Solr-specific index alter hook
Status: Needs review » Fixed

Coz sometimes we have complicated fields (property_type "struct") or need to use body and custom fields... if I understood the question correctly.

No, I don't think so, as I don't really understand your answer.
If I'm not mistaken, you said that you had defined an additional field in the schema.xml as <field name="body_summary" … /&gt> and wanted to index the node body summary in this field, instead of the dynamic field "t_body:summary". However, if you just define a field with <field name="t_body:summary" … /&gt>, this will have the same effect — i.e., use your field definition instead of the one for the dynamic field. This way, you can easily have fields with custom types, without changing the module's field mapping logic.

But, as said, this has its use cases anyways.

In my case i`m altering field mapping when indexing and searching. Your patch looks great. I think this will be enough. Thx.

OK, committed. Thanks for your input!

d.olaresko’s picture

No, I don't think so, as I don't really understand your answer.
If I'm not mistaken, you said that you had defined an additional field in the schema.xml as <field name="body_summary" … /&gt> and wanted to index the node body summary in this field, instead of the dynamic field "t_body:summary". However, if you just define a field with <field name="t_body:summary" … /&gt>, this will have the same effect — i.e., use your field definition instead of the one for the dynamic field. This way, you can easily have fields with custom types, without changing the module's field mapping logic.

But, as said, this has its use cases anyways.

it was simple example. In my case latitute solr library need two defined fields named as "lat" and "lng" and location module creates additional property`s for nodes (not fields, something like author settings or comment...).

Status: Fixed » Closed (fixed)

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