Hey,
In an implementation of ApacheSolr, i have come across the need to index fields beyond the core node fields which are included by the module, but yet are not CCK fields. This seems like something that might be useful to others beyond just my case, and hence have created a patch here.
My goals were:
- Ability to update the index of a specific node upon insert and modification
- Ability to index and query custom attributes of a node that may be added to the node object, but not be CCK fields
What was updated:
- Updated the 'update_index' and 'getNodesToIndex' methods to allow the passing of 'nid' as an optional secondary parameter
- In the 'update_index' method of the ApacheSolrUpdate class, added a check for additional fields to look for. This was accomplished in a similar fashion to how CCK fields were already being done, but this was done by exposing a new hook, so that each module can add their own custom attributes.
Ex.$addl_fields = module_invoke_all('apachesolr_node_fields');
How the features are implemented (via the search module that would be implemented, ex apachesolr_search.module):
- I do not have to implement the hook_update_index().
- In hook_nodeapi(), I can now invoke the updating of the index for a single node. Ex:
ApacheSolrUpdate::update_index('apachesolr', $node->nid); - Implemented the new hook_apachesolr_node_fields() to add the new attributes that one of the modules add to the node object via hook_nodeapi / load. Ex:
function modulename_apachesolr_node_fields() { $fields = array(); $fields['asset_category'] = array('name' => 'asset_category', 'field_type' => 'text'); return $fields; }//end - function
The result, after applying the patch:
- The module is completely backwards compatible with the original implementation of the module.
- But, applying this patch, and implementing the new hooks, we can now search by the custom attributes without modifying the module, or changing the schema.xml. Querying these new attributes is done in the same way as querying CCK fields was done, as:
ssasset_category:topsThis can also be done by adding these fields as blocks I suppose much like other CCK fields can be added as filters.
One other thing that i am working on now is adding the ability to sort via this search box, so that we can do something such as "solrsort:nid desc"
This is needed because I need to define a default sort order, since the score in my case is not useful.
Please let me know your thoughts, etc, and if you think this could be incorporated into the full module. It would be great to be able to know that I can keep up to date with the module if these necessary changes can make the way in.
-T
Comments
Comment #1
socki commentedSorry for the duplicate posting of this... There seems to be some sort of issue going on with d.o. at present as i originally got a blank page after pressing submit, so didn't realize it was actually saved properly.
Please see #334499: Patch to Index and query against non-core node / non-cck attributes
Comment #2
socki commentedComment #3
flexer commented+1
I've nodes with custom attributes too (no CCK)
Comment #4
socki commentedHey... better to track #334499: Patch to Index and query against non-core node / non-cck attributes