Skip to content

Commit

Permalink
Merge pull request #43 from NYULibraries/stage
Browse files Browse the repository at this point in the history
Stage
  • Loading branch information
ekate authored Oct 4, 2017
2 parents 0370425 + dc533f2 commit 1c2ec46
Show file tree
Hide file tree
Showing 4 changed files with 215 additions and 122 deletions.
60 changes: 20 additions & 40 deletions modules/dlts_solr/dlts_solr.module
Original file line number Diff line number Diff line change
@@ -1,37 +1,5 @@
<?php

/**
* http://api.drupal.org/api/drupal/modules--aggregator--aggregator.module/function/aggregator_cron/7
*/
function dlts_solr_cron() {
//drush_log(__FUNCTION__,'ok');
//$type = 'node';
//$env_id = 'solr';
//$bundle = 'dlts_series';
// apachesolr_index_node_solr_reindex($env_id, $bundle);
// while I test https://jira.nyu.edu/jira/browse/AWDL-207
//$bundle = 'dlts_book';
//$indexer_table = apachesolr_get_indexer_table($type);
//$id = 810;
// https://jira.nyu.edu/jira/browse/DLTSVIEWER-60
// http://stage-dl-pa.home.nyu.edu/viewer/books/brill_awdl000003/1
//$id = 2836;
//db_merge($indexer_table)->key(array('entity_type' => $type, 'entity_id' => $id))
//->insertFields(array('entity_type' => $type, 'entity_id' => $id, 'bundle' => $bundle, 'status' => 1))
//->fields(array('changed' => REQUEST_TIME))
//->execute();
//$id = 8091;
//db_merge($indexer_table)->key(array('entity_type' => $type, 'entity_id' => $id))
//->insertFields(array('entity_type' => $type, 'entity_id' => $id, 'bundle' => $bundle, 'status' => 1))
//->fields(array('changed' => REQUEST_TIME))
//->execute();
//$id = 2840;
//db_merge($indexer_table)->key(array('entity_type' => $type, 'entity_id' => $id))
//->insertFields(array('entity_type' => $type, 'entity_id' => $id, 'bundle' => $bundle, 'status' => 1))
//->fields(array('changed' => REQUEST_TIME))
//->execute();
}

function dlts_solr_node_update($node) {
$bundle = 'dlts_book';
if ($node->type == $bundle && $node->language != 'en') {
Expand Down Expand Up @@ -90,13 +58,6 @@ function dlts_solr_apachesolr_index_document_build(ApacheSolrDocument $document,
/** pass the document as reference */
dlts_solr_index_book($document, $entity, $entity_type, $env_id);
break;
case 'dlts_series' :
/** load utils */
module_load_include('inc', 'dlts_solr', 'inc/series');
/** pass the document as reference */
dlts_solr_index_series($document, $entity, $entity_type, $env_id);
break;

}
}

Expand Down Expand Up @@ -176,6 +137,16 @@ function seems_utf8( $str ) {
return true;
}

/**
*cleanup for arabic characters
*/
function dlts_solr_remove_special_cahrs($string) {
//remove modified letter turn comma
$string=preg_replace('/[\x{02BB}-\x{02BD}]+/u','',$string);
//remove special characters
$string=preg_replace('/(\,|\[|]|\.|}|\{)/','',$string);
return $string;
}
/**
* Taken from: https://core.trac.wordpress.org/browser/tags/4.4.2/src/wp-includes/formatting.php
* Converts all accent characters to ASCII characters.
Expand All @@ -188,6 +159,11 @@ function seems_utf8( $str ) {
* @return string Filtered string with replaced "nice" characters.
*/
function dlts_solr_remove_accents($string) {

//remove modified letter turn comma
$string=preg_replace('/[\x{02BB}-\x{02BD}]+/u','',$string);
//remove special characters
$string=preg_replace('/(\,|\[|]|\.|}|\{)/','',$string);
if ( !preg_match('/[\x80-\xff]/', $string) )
return $string;

Expand Down Expand Up @@ -395,6 +371,10 @@ function dlts_solr_remove_accents($string) {
//remove combined diacritics
$string=preg_replace('/[\x{0300}-\x{036f}]+/u','',$string);
//remove modified letter turn comma
$string=preg_replace('/\x{02BB}+/u','',$string);
$string=preg_replace('/[\x{02BB}-\x{02BD}]+/u','',$string);
//remove additional diacritics - enough with that need to do all this in solr
$string=preg_replace('/[\x{1E25}]+/u','h',$string);
//remove special characters
$string=preg_replace('/(\,|\[|]|\.|}|\{)/','',$string);
return $string;
}
45 changes: 31 additions & 14 deletions modules/dlts_solr/inc/book.inc
Original file line number Diff line number Diff line change
Expand Up @@ -131,6 +131,8 @@ function dlts_solr_index_book_partners($items = array(), &$document, &$entity, &
$document->addField('sm_' . $prefix . 'provider_label', $label);
}
if ($language == 'en') {
$document->addField('sm_sprovider_label', strtolower($label));
$document->addField('tum_provider_label', $label);
$document->addField('zm_partner',json_encode(array('name'=>$label,'code' => $code, 'nid' => $item->nid)));
$document->addField('zm_provider',json_encode(array('name'=>$label,'code' => $code, 'nid' => $item->nid)));
}
Expand Down Expand Up @@ -385,11 +387,9 @@ function dlts_solr_index_book(&$document, &$entity, $entity_type, $env_id) {
if (!empty($authors)) {
foreach ($authors as $index => $author) {
$searchableFields[] = $author;
$searchableFields[] = dlts_solr_remove_accents($author);
if ($index == 0) {
//$document->addField('ss_sauthor', dlts_solr_remove_accents(strtolower($author)));
$document->addField('ss_sauthor', strtolower(dlts_solr_remove_accents($author)));
$document->addField('iass_author', dlts_solr_remove_accents(strtolower($author)));
$document->addField('iass_author', $author);
}
$document->addField('sm_author', $author);
}
Expand Down Expand Up @@ -434,15 +434,16 @@ function dlts_solr_index_book(&$document, &$entity, $entity_type, $env_id) {
$publishers = $wrapper->field_publisher->value();
if (!empty($publishers)) {
foreach ($publishers as $publisher) {
$document->addField('sm_publisher', $publisher);
$searchableFields[] = dlts_solr_remove_accents($publisher);
$document->addField('sm_publisher', $publisher);
$searchableFields[] = $publisher;
}
}
unset($publishers);
unset($publisher);
/** Publication date (field_publication_date) */
/** single-value field */
$publication_date = $wrapper->field_publication_date->value();
$publication_date_text = $wrapper->field_publication_date_text->value();
if (!empty($publication_date) && !empty($publication_date['value'])) {
/** convert ISO format into UNIX timestamp */
$timestamp = strtotime($publication_date['value']);
Expand All @@ -453,27 +454,45 @@ function dlts_solr_index_book(&$document, &$entity, $entity_type, $env_id) {
$document->addField('sort_pubyear', $publication_year);
$document->addField('iass_pubyear', $publication_year);
$document->addField('iass_timestamp', $timestamp);
}
} else {
if (!empty($publication_date_text)) {
$publication_date_text_norm=preg_replace('(u|?)','0',$publication_date_text);
preg_match_all('\b\d{4}\b', $publication_date_text_norm, $years);
if(!empty($years)) {
foreach ($years as $index => $publication_year) {
$searchableFields[] = $publication_year;
if ($index == 0) {
$document->addField('sort_pubyear', $publication_year);
$document->addField('iass_pubyear', $publication_year);
}
$document->addField('dm_pubyear', date('Y-m-d\TG:i:s', strtotime($publication_year)));
}
}
}

}
}
unset($publication_date);
unset($publication_year);
/** Publication date (field_publication_date) */
/** single-value field */
$publication_date_text = $wrapper->field_publication_date_text->value();

if (!empty($publication_date_text)) {
/** @TODO: Find the right field for this field */
$document->addField('ss_publication_date_text', $publication_date_text);
$document->addField('ss_pubdate', $publication_date_text); // remove this?
$document->addField('ss_spubdate', strtolower($publication_date_text));
} else {

}
unset($publication_date_text);
/** Publication location (field_publication_location) */
/** single-value field */
$publication_location = $wrapper->field_publication_location->value();
if (!empty($publication_location)) {
$searchableFields[] = dlts_solr_remove_accents($publication_location);
$searchableFields[] = $publication_location;
$document->addField('ss_publication_location', $publication_location);
$document->addField('ss_publocation',dlts_solr_remove_accents($publication_location)); // remove this? @kate- when search options are fixed
$document->addField('ss_spublocation', dlts_solr_remove_accents($publication_location));
$document->addField('ss_publocation', $publication_location); // remove this? @kate- when search options are fixed
}
unset($publication_location);
/** Subject (field_subject) */
Expand All @@ -482,10 +501,9 @@ function dlts_solr_index_book(&$document, &$entity, $entity_type, $env_id) {
if (!empty($subjects)) {
foreach ($subjects as $index=>$subject) {
$document->addField('sm_subject_label', $subject->name);
$searchableFields[] = dlts_solr_remove_accents($subject->name);
$searchableFields[] = $subject->name;
if ($index == 0) {
$document->addField('ss_ssubject', strtolower(dlts_solr_remove_accents($subject->name)));
$document->addField('iass_subject', strtolower(dlts_solr_remove_accents($subject->name)));
$document->addField('iass_subject', $subject->name);
}
$document->addField('zm_subject',json_encode(array('name'=>$subject->name,'tid' => $subject->tid, 'vid' => $subject->vid)));
}
Expand Down Expand Up @@ -525,7 +543,6 @@ function dlts_solr_index_book(&$document, &$entity, $entity_type, $env_id) {
unset($language);

/** Single value fields */
//Remove combining diacritics
$document->addField('ss_title', $book_field_title);
// Strip HTML Tags
$title_sort = strip_tags($book_field_title);
Expand Down
Loading

0 comments on commit 1c2ec46

Please sign in to comment.