Skip to content

Commit

Permalink
CS-5528: Adds subtype method, cleans out code
Browse files Browse the repository at this point in the history
Conflicts:
	newscoop/include/smarty/campsite_plugins/function.build_solr_fq.php

CS-5528: Updates indexing code
  • Loading branch information
m038 committed Jan 22, 2015
1 parent 2e958ff commit 798b37e
Show file tree
Hide file tree
Showing 16 changed files with 178 additions and 292 deletions.
3 changes: 0 additions & 3 deletions newscoop/application/configs/parameters/parameters.yml
Original file line number Diff line number Diff line change
Expand Up @@ -146,9 +146,6 @@ parameters:
file_num_dirs_level_1: 1000
file_num_dirs_level_2: 1000
subscriptions.service.class: "Newscoop\Services\SubscriptionService"
search.article:
type: ["news"]
rendition: ''
plugins:
internal_memory_limit: ''
scheduler:
Expand Down
8 changes: 4 additions & 4 deletions newscoop/application/configs/services/services.yml
Original file line number Diff line number Diff line change
Expand Up @@ -164,16 +164,16 @@ services:
arguments: ["@service_container"]
indexer.article:
class: Newscoop\Search\Indexer
arguments: ["@service_container", "@search.article", "@article.repository"]
arguments: ["@service_container", "@search.article", "@article.repository", "indexer.article"]
indexer.comment:
class: Newscoop\Search\Indexer
arguments: ["@service_container", "@search.comment", "@comment.repository"]
arguments: ["@service_container", "@search.comment", "@comment.repository", "indexer.comment"]
indexer.user:
class: Newscoop\Search\Indexer
arguments: ["@service_container", "@search.user", "@user.repository"]
arguments: ["@service_container", "@search.user", "@user.repository", "indexer.user"]
search.article:
class: Newscoop\Article\SearchService
arguments: ["@webcode", "@image.rendition", "@article.link", "@em", "%search.article%"]
arguments: ["@webcode", "@image.rendition", "@article.link", "@em"]
search.comment:
class: Newscoop\Comment\SearchService
arguments: ["@article.link"]
Expand Down

This file was deleted.

This file was deleted.

This file was deleted.

68 changes: 57 additions & 11 deletions newscoop/library/Newscoop/Article/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,8 @@ class SearchService implements ServiceInterface
* @var array
*/
protected $config = array(
'rendition' => null
'rendition' => null,
'type' => array('all')
);

/**
Expand Down Expand Up @@ -87,6 +88,16 @@ public function getType()
return 'article';
}

/**
* Return sub type for the document
*
* @return string identifier
*/
public function getSubType(DocumentInterface $article)
{
return $article->getType();
}

/**
* Test if article is indexed
*
Expand Down Expand Up @@ -129,24 +140,37 @@ public function getDocument(DocumentInterface $article)

$doc = array(
'id' => $this->getDocumentId($article),
'title' => $article->getTitle(),
'number' => $article->getNumber(),
'type' => $article->getType(),
'published' => gmdate(self::DATE_FORMAT, $article->getPublishDate()->getTimestamp()),
'updated' => gmdate(self::DATE_FORMAT, $article->getDate()->getTimestamp()),
'author' => array_map(function($author) {
return $author->getFullName();
}, (is_array($article->getArticleAuthors())) ? $article->getArticleAuthors() : array()),
'webcode' => $webcode,
'title' => $article->getTitle(),
'updated' => gmdate(self::DATE_FORMAT, $article->getDate()->getTimestamp()),
'published' => gmdate(self::DATE_FORMAT, $article->getPublishDate()->getTimestamp()),
'image' => $image ? $image['src'] : null,
'link' => $this->linkService->getLink($article),

'language' => $article->getLanguageCode(),
'language_id' => $article->getLanguageId(),

'publication_number' => $article->getPublication() ? $article->getPublication()->getId() : null,
'issue_number' => $article->getIssue() ? $article->getIssue()->getNumber() : null,
// TODO: check if we can remove one
'section_number' => $article->getSection() ? $article->getSection()->getNumber() : null,
'section_id' => $article->getSection() ? $article->getSection()->getNumber() : null,

'section' => $this->linkService->getSectionShortName($article),
'section_name' => ($article->getSection()) ? $article->getSection()->getName() : null,
'section_id' => $article->getSectionId(),
'keyword' => explode(',', $article->getKeywords()),
'topic' => array_values($article->getTopicNames()),
'section_name' => $article->getSection() ? $article->getSection()->getName() : null,

'authors' => array_map(function($author) {
return $author->getFullName();
}, (is_array($article->getArticleAuthors())) ? $article->getArticleAuthors() : array()),
'keywords' => explode(',', $article->getKeywords()),
'topics' => array_values($article->getTopicNames()),
'switches' => $this->getArticleSwitches($article),
);

$this->addDataFields($doc, $article);

return array_filter($doc);
}

Expand Down Expand Up @@ -195,4 +219,26 @@ public function getArticleSwitches($article)
}
}
}

/**
* Add field properties to document
*
* @param array $doc
*
* @return array
*/
private function addDataFields(array $doc, $article)
{
$articleData = new \ArticleData($article->getType(), $article->getNumber(), $article->getLanguageId());
if (count($articleData->getUserDefinedColumns()) == 0) {
return $doc;
}

$fields = array();
foreach ($articleData->getUserDefinedColumns() as $column) {
$doc[$column->getPrintName()] = $articleData->getFieldValue($column->getPrintName());
}

return $doc;
}
}
12 changes: 12 additions & 0 deletions newscoop/library/Newscoop/Comment/SearchService.php
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ class SearchService implements ServiceInterface

/**
* @param Newscoop\Article\LinkService $articleLinkService
* @param array $config
*/
public function __construct(LinkService $articleLinkService)
{
Expand All @@ -40,6 +41,16 @@ public function getType()
return 'comment';
}

/**
* Return type for this search service
*
* @return string identifier
*/
public function getSubType(DocumentInterface $comment)
{
return 'comment';
}

/**
* Test if comment is indexed
*
Expand Down Expand Up @@ -72,6 +83,7 @@ public function getDocument(DocumentInterface $comment)
{
return array(
'id' => $this->getDocumentId($comment),
'number' => $comment->getId(),
'type' => 'comment',
'subject' => $comment->getSubject(),
'message' => $comment->getMessage(),
Expand Down
Loading

0 comments on commit 798b37e

Please sign in to comment.