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

 
Luật Steve Jobs - Vì sao nhà sáng lập lại chính là nhà lãnh đạo tốt nhất?

Luật Steve Jobs - Vì sao nhà sáng lập lại chính là nhà lãnh đạo tốt nhất?

Vị CEO quá cố của Apple rất đặc biệt, nhưng một bài học ta rút ra từ quá khứ của ông ấy thì còn có ảnh hưởng hơn nhiều, đến mức có thể gọi thành “luật” (bất thành văn, đương nhiên).

Nhìn lại 12 tháng đầy những biến động của Apple

Nhìn lại 12 tháng đầy những biến động của Apple

2011 có thể là năm đáng nhớ nhất trong lịch sử Apple, với nhiều sự kiện và biến động. Ngoài những thành công đạt được với các sản phẩm mới...

6 Tools for Windows Maintenance

6 Tools for Windows Maintenance

In windows most of us are downloading, deleting and move file from here to there, and after this your windows has so many dump files...

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

 

Diet con trung