Skip to content

Commit

Permalink
Merge branch 'bugfixes'
Browse files Browse the repository at this point in the history
  • Loading branch information
jkim01 committed Feb 26, 2019
2 parents e3a3ad0 + 56297ec commit 7f10c65
Show file tree
Hide file tree
Showing 2 changed files with 46 additions and 31 deletions.
20 changes: 20 additions & 0 deletions classes/AlgoliaEngine.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -126,4 +126,24 @@ public function clear_index()
return $e->getMessage();
}
}

/**
* Deletes an object by distictId
* @param $distinctId
* @return bool
*/
public function deleteByDistinctId($distinctId)
{
$index = $this->client->initIndex($this->index);

try {
$index->deleteBy([
'filters' => 'distinctId:' . $distinctId,
]);
} catch (AlgoliaException $e) {
return $e->getMessage();
}

return true;
}
}
57 changes: 26 additions & 31 deletions classes/AlgoliaService.inc.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,16 @@
define('ALGOLIA_INDEXINGSTATE_DIRTY', true);
define('ALGOLIA_INDEXINGSTATE_CLEAN', false);

// // The max. number of articles that can
// // be indexed in a single batch.
// The max. number of articles that can
// be indexed in a single batch.
define('ALGOLIA_INDEXING_MAX_BATCHSIZE', 2000);

// Number of words to split
define('ALGOLIA_WORDCOUNT_SPLIT', 250);

import('classes.search.ArticleSearch');
import('plugins.generic.algolia.classes.AlgoliaEngine');
import('lib.pkp.classes.config.Config');

class AlgoliaService {
var $indexer = null;
Expand Down Expand Up @@ -176,7 +180,9 @@ function pushChangedArticles($batchSize = ALGOLIA_INDEXING_MAX_BATCHSIZE, $journ
unset($toDelete);
$this->indexer->clear_index();
}else{
$this->indexer->delete($toDelete);
foreach($toDelete as $delete){
$this->indexer->deleteByDistinctId($delete['distinctId']);
}
}

foreach($toAdd as $add){
Expand All @@ -199,7 +205,9 @@ function deleteArticleFromIndex($articleId) {

$toDelete = array();
$toDelete[] = $this->buildAlgoliaObjectDelete($articleId);
$this->indexer->delete($toDelete);
foreach($toDelete as $delete){
$this->indexer->deleteByDistinctId($delete['distinctId']);
}
}

/**
Expand Down Expand Up @@ -328,13 +336,13 @@ function buildAlgoliaObjectDelete($articleOrArticleId){
if(!is_numeric($articleOrArticleId)) {
return array(
"objectAction" => "deleteObject",
"objectID" => $articleOrArticleId->getId(),
"distinctId" => $articleOrArticleId->getId(),
);
}

return array(
"objectAction" => "deleteObject",
"objectID" => $articleOrArticleId,
"distinctId" => $articleOrArticleId,
);
}

Expand Down Expand Up @@ -485,27 +493,7 @@ function getGalleyHTML($article){
foreach($galleys as $galley){
if($galley->getFileType() == "text/html"){
$submissionFile = $galley->getFile();
$contents = file_get_contents($submissionFile->getFilePath());

$contents = preg_replace(
'/([Ss][Rr][Cc]|[Hh][Rr][Ee][Ff]|[Dd][Aa][Tt][Aa])\s*=\s*"([^"]*' . $pattern . ')"/',
'\1="' . $fileUrl . '"',
$contents
);

// Replacement for Flowplayer
$contents = preg_replace(
'/[Uu][Rr][Ll]\s*\:\s*\'(' . $pattern . ')\'/',
'url:\'' . $fileUrl . '\'',
$contents
);

// Replacement for other players (ested with odeo; yahoo and google player won't work w/ OJS URLs, might work for others)
$contents = preg_replace(
'/[Uu][Rr][Ll]=([^"]*' . $pattern . ')/',
'url=' . $fileUrl ,
$contents
);
$contents .= file_get_contents($submissionFile->getFilePath());
}
}

Expand All @@ -515,12 +503,19 @@ function getGalleyHTML($article){
function chunkContent($content){
$data = array();
$updated_content = html_entity_decode($content);
$chunked_content = explode("</p>", wordwrap($updated_content, ALGOLIA_WORDCOUNT_SPLIT));

foreach($chunked_content as $chunked){
if($chunked){
$data[] = strip_tags($chunked);
if($updated_content){
$temp_content = str_replace("</p>", "", $updated_content);
$chunked_content = preg_split("/<p[^>]*?(\/?)>/i", $temp_content);

foreach($chunked_content as $chunked){
if($chunked){
$tagless_content = strip_tags($chunked);
$data[] = trim(wordwrap($tagless_content, ALGOLIA_WORDCOUNT_SPLIT));
}
}
}else{
$data[] = trim(strip_tags($updated_content));
}

return $data;
Expand Down

0 comments on commit 7f10c65

Please sign in to comment.