Skip to content

Commit

Permalink
Ignore empty titles
Browse files Browse the repository at this point in the history
  • Loading branch information
almasaeed2010 committed Apr 20, 2018
1 parent ef9e252 commit 6a9f456
Show file tree
Hide file tree
Showing 3 changed files with 36 additions and 25 deletions.
45 changes: 22 additions & 23 deletions includes/Elasticsearch/ESInstance.php
Original file line number Diff line number Diff line change
Expand Up @@ -100,10 +100,10 @@ public function setWebsiteSearchParams(
$queries = [];

$queries[] = [
"query_string" => [
"default_field" => "content",
"query" => $this->sanitizeQuery($search_terms),
"default_operator" => "AND",
'query_string' => [
'default_field' => 'content',
'query' => $this->sanitizeQuery($search_terms),
'default_operator' => 'AND',
],
];

Expand All @@ -112,42 +112,41 @@ public function setWebsiteSearchParams(

if (in_array('website', $indices) && !$force_entities_only) {
$queries[1]['query_string'] = [
"default_field" => "type",
"query" => '"' . $node_type . '"',
"default_operator" => "AND",
'default_field' => 'type',
'query' => '"' . $node_type . '"',
'default_operator' => 'AND',
];
}

if (in_array('entities', $indices)) {
$queries[1]['query_string'] = [
"default_field" => "bundle_label",
"query" => '"' . $node_type . '"',
"default_operator" => "AND",
'default_field' => 'bundle_label',
'query' => '"' . $node_type . '"',
'default_operator' => 'AND',
];
}

if (in_array('entities', $indices) && in_array('website', $indices) && !$force_entities_only) {
$queries[1]['query_string'] = [
"fields" => ["type", "bundle_label"],
"query" => '"' . $node_type . '"', // Gene or mRNA (feature,Gene)
"default_operator" => "AND",
'fields' => ['type', 'bundle_label'],
'query' => '"' . $node_type . '"', // Gene or mRNA (feature,Gene)
'default_operator' => 'AND',
];
}
}

$query = [
"bool" => [
"must" => $queries,
"filter" => []
'bool' => [
'must' => $queries,
],
];

$highlight = [
"pre_tags" => ["<em><b>"],
"post_tags" => ["</b></em>"],
"fields" => [
"content" => [
"fragment_size" => 150,
'pre_tags' => ['<em><b>'],
'post_tags' => ['</b></em>'],
'fields' => [
'content' => [
'fragment_size' => 150,
],
],
];
Expand Down Expand Up @@ -302,14 +301,14 @@ public function setIndexParams($index_name, $shards = 5, $replicas = 0,
* @return array
* @throws \Exception
*/
public function search($return_source = false) {
public function search($return_source = FALSE) {
if (empty($this->searchParams)) {
throw new Exception('Please build search parameters before attempting to search.');
}

$hits = $this->client->search($this->searchParams);

if($return_source) {
if ($return_source) {
return $hits;
}

Expand Down
8 changes: 7 additions & 1 deletion includes/Jobs/EntitiesIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -168,9 +168,15 @@ protected function loadContent($records) {
$content = $prev_entity['_source']['content'] + $content;
}

// Ignore entities with empty titles
$title = trim($entity->title);
if (empty($title)) {
continue;
}

$all[] = (object) [
'entity_id' => $entity->id,
'title' => $entity->title,
'title' => $title,
'bundle_label' => $record->bundle_label,
'content' => $content,
];
Expand Down
8 changes: 7 additions & 1 deletion includes/Jobs/NodesIndexJob.php
Original file line number Diff line number Diff line change
Expand Up @@ -110,9 +110,15 @@ protected function loadContent($records) {
continue;
}

// Ignore nodes with empty titles
$title = trim($record->title);
if(empty($title)) {
continue;
}

$all[] = (object) [
'nid' => $record->nid,
'title' => $record->title,
'title' => $title,
'type' => $record->type,
'content' => $this->cleanHTML($content),
];
Expand Down

0 comments on commit 6a9f456

Please sign in to comment.