This is just for future reference.
If you're using the flag module you can index flags like this:
function hook_apachesolr_update_index(&$document, $node) {
$flag_id = 1; // You have to look up your flag id yourself.
$count = db_result(db_query("SELECT count FROM {flag_counts} f WHERE content_type = 'node' AND content_id = %d AND fid = %d", $node->nid, $flag_id));
// Note the is_ prefix is important; it tells Solr to make a new dynamic field that is a single integer.
$document->is_flag_count = $count;
}
Then you need to guarantee that the flags get updated in the index later, so every time a node gets flagged you mark it for re-indexing.
/**
* Implementation of hook_flag from the flag module so that we can reindex nodes that get flagged.
*/
function hook_flag($op, $flag, $content_id, $account) {
if ($flag->content_type == 'node') {
// In node_load's static caching we trust.
$node = node_load($content_id);
_apachesolr_nodeapi_update($node);
}
}
Comments
Comment #1
Scott Reynolds commentedDon't you want to mark the node instead of _apachesolr_nodeapi_update() ?
The nodeapi_update checks if the node should be removed from the index based on $node->status. Flag doesn't change that.
Heres how i did it for a specific flag name.
Comment #2
robertdouglass commentedIndeed, that's much nicer. Thanks!
Comment #4
maxmic commentedPlease, Can you help me? Where can I put the above code? On a new module? in Flag module.
Many thanks,
Massimo
Comment #5
djalloway commentedIf one wanted to Bias Negatively nodes which are flagged, what would I need to adjust in the above code to do so?
Any pointers in the right direction would be appreciated!
Comment #6
bibo commentedI wonder how to put user-specific flagging (which could be used to say "I like this content") into Solr.
Probably not with this approach?
Comment #7
a_c_m commentedBeing able to change results based on flag would be great.
Comment #8
cpliakas commentedComments #4 - #7, this issue is closed and these are separate topics. If you want to discuss these support / feature requests it would be better to open separate issues so they can be tracked individually.
Thanks,
Chris