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

 
Xôn xao vụ bán đấu giá tài liệu thành lập Apple

Xôn xao vụ bán đấu giá tài liệu thành lập Apple

Trang Bloomberg vừa đưa tin nhà tổ chức bán đấu giá Sotheby’s (Mỹ) đang chuẩn bị đem ra đấu giá bản tài liệu gốc dài ba trang về quyết định thành lập công ty máy tính Apple do bộ ba Steve Jobs, Steve Wozniak và Ron Wayne

Hướng dẫn tạo multi-step forms có sử dụng ctools multistep wizard

In the previous post I gave an example of Ctools modal API as being operated with a single form. In this one you'll be given an insight into my experiences with another powerful tool, namely Ctools multistep wizard as being used with or without the modal API involvement.

Allow Drupal Users to Manage Their Own Content

Cho phép Drupal Users tự quản lý nội dung của mình

This week's tutorial is the first of a two-parter. We've had several students in our classes looking to build websites with multiple content authors ... blogs, newspapers, university sites and more. A common request is to improve Drupal's default handling of nodes.

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

 

Diet con trung