Skip to content

Instantly share code, notes, and snippets.

@dergachev
Last active August 29, 2015 13:57
Show Gist options
  • Save dergachev/9650039 to your computer and use it in GitHub Desktop.
Save dergachev/9650039 to your computer and use it in GitHub Desktop.
Makefile for partial re-indexing while working with search_api
#============================================================================
# Utilities
#============================================================================
num_items_to_index = $(shell drush sqlq "SELECT COUNT(*) FROM search_api_item;" --extra=--skip-column-names)
index_name = coursecal_content
index_id = $(shell drush php-eval 'print search_api_index_load("$(index_name)")->id')
status:
drush sapi-s $(index_name)
reset-php:
drush php-eval "module_load_include('install', 'search_api'); search_api_enable();"
truncate:
drush sapi-c $(index_name)
drush sqlq "TRUNCATE TABLE search_api_item;"
index_debug:
drush -d sapi-i $(index_name)
index:
drush -d sapi-i $(index_name) 2>&1 | grep study_search | pv -l -s $(num_items_to_index)
commit:
drush php-eval 'print_r(search_api_index_load("$(index_name)")->server()->commit())'
# 00:06:33 (when pruned)
#============================================================================
# Reset to all nodes
#============================================================================
populate-all: truncate
drush sapi-c $(index_name)
drush sqlq "INSERT into search_api_item SELECT nid as item_id, $(index_id) AS index_id, 1 as changed from node;"
$(MAKE) status # 78033
populate-active: truncate
drush sqlq "INSERT INTO search_api_item \
SELECT nid as item_id, $(index_id) AS index_id, 1 as changed \
FROM node \
WHERE type IN ('publication_page', 'catalog', 'program', 'faculty') AND status = 1;"
$(MAKE) status #24051
#============================================================================
# Include only a single node (nid 21307 is a catalog) (60754 is publication_page)
#============================================================================
populate-several: truncate
drush sqlq "INSERT INTO search_api_item VALUES (21307, $(index_id), 1), (60754, $(index_id), 1);"
drush sapi-i
#============================================================================
# Include all indexed nodes (24k instead of 78k, will save a few minutes)
#============================================================================
populate-pruned: populate-pruned-banner populate-pruned-documentum
$(MAKE) status # 5415
populate-pruned-banner: truncate
drush sqlq "\
INSERT INTO search_api_item \
SELECT n.nid, $(index_id), 1 \
FROM node n \
INNER JOIN field_data_field_faculty_code f \
ON n.nid = f.entity_id AND f.field_faculty_code_value IN ( 'EN' ) \
WHERE n.type IN ('catalog', 'program') AND n.status = 1 \
;\
"
populate-pruned-documentum: truncate
drush sqlq "\
INSERT INTO search_api_item \
SELECT n.nid, $(index_id), 1 \
FROM node n \
WHERE n.type = 'publication_page' \
AND n.status = 1 \
;\
"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment