1

We're using Views to display our search_api_solr results. We'd like to be able to show these results by radioactivity (popularity) sort order.

The radioactivity field is one of several fields indexed by Solr so that it can be used by the Solr views for sorting.

The problem is, the radioactivity value that gets indexed by solr only gets updated when the entity gets indexed. The entity only gets indexed when it gets changed (node_update), or when the Solr index is cleared and everything is reindexed again. Having an entities radioactivity energy adjusted by visiting the entity, does not trigger solr to reindex the entity - and probably rightly so.

I've tried adding a relationship in the Search View to node, but that isn't available as a "search index" view type.

Does anyone have any other suggestions for solving this? There doesn't seem to be a radioactivity hook that lets you execute your own code, i.e. update search_api_item table to say its changed.

2 Answers 2

0

As you say there's no API, so you're probably going to have to resort to patching the module.

There are at least two places you'll need to make additions as far as I can tell:

  • _radioactivity_update_energy()
  • radioactivity_cron()

I would suggest adding your own hook which gets fired whenever an entity is updated in either of those functions, and perform the search indexing there.

You should have a good think about the values you use for half lives/Solr processing delays if you choose to implement it like this. If your values for those settings aren't sensible you could end making the changes without actually seeing any effect. Also, depending on the amount of traffic the site receives, you could slow your server down quite a bit doing this.

0

If you want to add a single entity, then following code can be helpful:

search_api_track_item_change('node', array($entity_id));
$index = search_api_index_load('SEARCH_API_INDEX_NAME');
$indexed = search_api_index_specific_items($index, array($entity_type.'/'.$entity_id));

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.