Issue: Repeatable
Modules: Search API Solr search 7.x-1.0-rc1, Search API 7.x-1.0, Entity API 7.x-1.0-rc1
Goal: Looking for suggested code tweaks or alternate strategies to ensure that after indexing items to solr programmatically these newly indexed items do not drop from the index.
Using my own custom module in Drupal 7.2, I am directly indexing some taxonomy items into a solr server node item index via code using the search_api_solr SearchApiSolrService indexItems method. I map the relevant individual taxonomy term data to appropriate node item fields in the index.
I seem to successfully index my items. No errors thrown to watchdog. And those apparently successfully indexed items appear in my site's solr search results, but these newly indexed items immediately start to go missing from the solr search results after first appearing in the solr search results one time only.
I run commit after the indexing, but the HTTP 200 response does not seem to indicate success of the commit or not.
Is there an example anywhere that shows how to correctly index items directly to a solr index from Drupal 7 using functions from Search API Solr or Search API module?
From a function I run in a hook_search_api_index_items_alter here is a code snippet showing my index effort to solr:
// collected taxonomy terms to index
// now via loop passing taxonomy term info to indexItems
foreach($terms as $term) {
$term_indexable = taxonomy_term_load($term->tid);
// create unique id for term to avoid clash with nodes in index
$base_id = $term_indexable->tid;
$new_id = $base_id + 99000;
$my_id = $new_id;
if( is_object($term_indexable) && !in_array($my_id,$already_indexed_items_ids) ) {
$my_title = $term_indexable->name;
$my_description = $term_indexable->description;
$good_description = ($my_description==''||!isset($my_description))? " " : $my_description;
$my_term = $term_indexable->vocabulary_machine_name;
// Add items to solr index.
// This is the public search api solr index items function found in service.inc file
// Accepts params: index obj, array of item objects to index
$new_item = new stdClass();
$new_item->title = array('value'=>$my_title,'type'=>'text');
$new_item->term_id = array('value'=>$my_id,'type'=>'integer');
$new_item->term_name = array('value'=>$my_title,'type'=>'text');
$new_item->description = array('value'=>$good_description,'type'=>'text');
$new_item->type = array('value'=>$my_term,'type'=>'string');
$new_items[$my_id] = $new_item;
$indexed_items_result_set = $server_obj->indexItems($index,$new_items);
// Capture all taxonomy term ids as indexed
$newly_indexed_items_ids[] = $my_id;
} // if term is indexable
}// for each term
$indexed_items_commit_result = $server_obj->commit();
//$indexed_items_commit_result = $server_obj->optimize();
Here is the HTTP response from the commit:
Apache_Solr_Response Object
(
[_response:protected] => Apache_Solr_HttpTransport_Response Object
(
[_statusCode:Apache_Solr_HttpTransport_Response:private] => 200
[_statusMessage:Apache_Solr_HttpTransport_Response:private] =>
OK
[_mimeType:Apache_Solr_HttpTransport_Response:private] =>
text/plain
[_encoding:Apache_Solr_HttpTransport_Response:private] => utf-8
[_responseBody:Apache_Solr_HttpTransport_Response:private] =>
{"responseHeader":{"status":0,"QTime":153}}
)
[_isParsed:protected] =>
[_parsedData:protected] =>
[_createDocuments:protected] => 1
[_collapseSingleValueArrays:protected] => 1
)I cannot find solr documentation that tells me what the commit response should contain to tell me the commits were successful.
For further background, I also run several custom data alterations on all the indexed items.
I am adding these taxonomy terms directly into the node items index like this so that the taxonomy term pages can be uniformly indexed with nodes and become part of facets.
Comments
Comment #1
xpsusa commentedComment #2
OanaIlea commentedThis issue was closed due to lack of activity over a long period of time. If the issue is still acute for you, feel free to reopen it and describe the current state.