Bỏ qua Search API đi Reindex a Node / an Entity Drupal 7

Bỏ qua Search API đi Reindex a Node / an Entity Drupal 7

Search API (Drupal 7)

By default Search API (Drupal 7) reindexes a node when the node gets updated. But what if you want to reindex a node / an entity on demand or via some other hook i.e. outside of update cycle? Turned out it is a quite simple exercise. You just need to execute this function call whenever you want to reindex a node / an entity:

>> Thêm classes vào links trong Drupal 8

>> Hướng dẫn Creating a Custom Filter trong Drupal 8

>> Giới thiệu tốc độ Drupal website với cloudflare

search_api_track_item_change('node', array($nid));

See this snippet at dropbucket: http://dropbucket.org/node/1600search_api_track_item_change marks the items with the specified IDs as "dirty", i.e., as needing to be reindexed. You need to supply this function with two arguments: entity_type ('node' in our example) and an array of entity_ids you want to be reindexed. Once you've done this, Search API will take care of the rest as if you've just updated your node / entity. Additional tip: In some cases, it's worth to clear field_cache for an entity before sending it to reindex:

// Clear field cache for the node.

cache_clear_all('field:node:' . $nid, 'cache_field');

// Reindex the node.

search_api_track_item_change('node', array($nid));

This is the case, when you manually save / update entity values via sql queries and then want to reindex the result (for example, radioactivity module doesn't save / update a node, it directly manipulates data is sql tables). That way you'll ensure that search_api reindexes fresh node / entity and not the cached one.

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Tommy Tran

Tommy owner Express Magazine

Drupal Developer having 9+ year experience, implementation and having strong knowledge of technical specifications, workflow development. Ability to perform effectively and efficiently in team and individually. Always enthusiastic and interseted to study new technologies

  • Skype ID: tthanhthuy

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
10 lí do khiến Adobe thua cuộc trong cuộc chiến Flash di động với Apple

10 lí do khiến Adobe thua cuộc trong cuộc chiến Flash di động với Apple

Vừa qua, Adobe đã quyết định sẽ không còn hỗ trợ FLash Player cho các trình duyệt web di động nữa. Qua đó, ta có thể thấy rằng Adobe đã thua Apple trong cuộc chiến căng thẳng kéo dài về nền tảng phát triển ứng dụng Web này.

Giới thiệu module Organic Groups trong Drupal 6

Giới thiệu module Organic Groups trong Drupal 6

OG allows users to create and manage their own groups. Other members can then join those groups and share content either privately or publicly.

Hướng dẫn Debug: Stop Thinking and Look năm 2015

Hướng dẫn Debug: Stop Thinking and Look năm 2015

Debugging is a discipline that requires patience, and a fervent attention to detail. 

Công ty diệt chuột T&C

 

Diet con trung