Posts

Showing posts from January, 2017

Drupal solr: Update specific document directly to solr index.

Problem:   How to update specific solr index document. Requirement: Drupal 7.x Search API Solr Search Solr server should enabled and running(Version 4.9 or more) CURL Solution: $update = array( 'id' => '',// Document id "field_name" => array( 'set' => ''//Value ) ); $update = json_encode(array($update)); $ch = curl_init('http://localhost:8983/solr/collection1/update?commit=true'); curl_setopt($ch, CURLOPT_POST, true); curl_setopt($ch, CURLOPT_POSTFIELDS, $update); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json')); $output = json_decode(curl_exec($ch)); $responseCode = curl_getinfo($ch, CURLINFO_HTTP_CODE); curl_close($ch); if ($responseCode == 200) { echo 'SOLR: Updated successfully for id:' . $doc_id . ' (query time: ' . $output->responseHeader->QTime . 'ms).<br>'; } else

Drupal Solr: How to add custom filter in solr

Image
Problem: How to add our own custom filter in drupal solr index. Requirement: Drupal 7.x Search API Solr Search Solr server should enabled and running. Solution: By default S earch API solr has very less filters like Bundle Filter, Node filter, Node Access etc. Many times we require our custom filter base on some value or field. Like in this post,my requirement is to exclude those articles which title include " Eating Fish " words. So Lets start. Step 1:   Create on custom module solr_filter and in solr_filter.module file implement  hook_search_api_alter_callback_info . /** * Implement hook_search_api_alter_callback_info * @return type */ function solr_filter_search_api_alter_callback_info() { $callbacks['exclude_article_1'] = array( 'name' => t('Exclude Article'), 'description' => t('Exclude article which title include words "Eating Fish"'), 'class' =>

Drupal Solr: How to add custom field in solr fields.

Image
This time I am going with Drupal Solr. You can know more about what is solr and how it is suitable for your web site. Problem : How to add custom field(Article Ownership Text) in solr search index. Requirement: Drupal 7.x Search API Solr Search Solr server should enabled and running. Solution: You can see in above image I have created the Article Index and in field list it shows all fields which is related to Article content type. Now I want my custom code field "show legal ownership text" for every article. Step 1: Create on custom module solr_field and in solr_field.module file implement  hook_entity_property_info_alter . /** * Implements hook_entity_property_info_alter(). */ function solr_field_entity_property_info_alter(&$info) { $info['node']['properties']['legal_text'] = array( 'type' => 'text', 'label' => t('Legal Text'), 'sanitized' =&g