1

My goal is to use Search API so that I can create a custom search page using Views. I want to add the "rating" widget (rate module), but there is no way to include it in the Search API fields. Thus, I tried to fix it by adding custom field to Search API index.

function rate_entity_property_info_alter(&$info) {
  $info['node']['properties']['widget'] = array(
    'label' => t('Rating widget'),
    'description' => t('Rating widget'),
    'getter callback' => 'display_widget',
  );
}
function display_widget($node) {
     print rate_generate_widget('1', 'node', $node->nid);
}

However, I am getting AJAX errors

enter image description here

and problems with displaying widgets.

enter image description here

Please can someone help me to solve this problem.

Thanks

1
  • Is this a Solr based search? – Kevin Sep 6 '16 at 23:18
0

If this is a Solr/ElasticDB search backend under Search API, you could try this approach.

Create a view mode on the node type (ex. Search Result), then create a template with the html markup when rendered for it. Include all the fields in the display and configure the formatters as you want them.

Next, install Search API View Modes, and configure that view mode to be indexed. It will render that node before indexing it into a new field (search server side). Then, you can create a view display that shows that field, which is just HTML, and bypass some of these issues.

I use this method in every Search API based search I encounter. You're basically storing the rendered HTML on the search server, then printing that as the result.

I can't tell if you are on Drupal 7 or 8. Note that the 8.x branch 'works' but may have some bugs. I have only been able to test simple setups and not use it on production like the 7.x branch.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

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