Skip to content

Commit

Permalink
Changing format handling in Smart Search
Browse files Browse the repository at this point in the history
  • Loading branch information
Hackwar committed Apr 3, 2019
1 parent 3bf41ce commit 9d8ae45
Show file tree
Hide file tree
Showing 4 changed files with 52 additions and 89 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,13 @@ class FinderIndexerDriverMysql extends FinderIndexer
* Method to index a content item.
*
* @param FinderIndexerResult $item The content item to index.
* @param string $format The format of the content. [optional]
*
* @return integer The ID of the record in the links table.
*
* @since 3.0
* @throws Exception on database error.
*/
public function index($item, $format = 'html')
public function index($item)
{
// Mark beforeIndexing in the profiler.
static::$profiler ? static::$profiler->mark('beforeIndexing') : null;
Expand Down Expand Up @@ -158,39 +157,21 @@ public function index($item, $format = 'html')
foreach ($properties as $property)
{
// Check if the property exists in the item.
if (empty($item->$property))
if (empty($item->{$property['property']}))
{
continue;
}

// Tokenize the property.
if (is_array($item->$property))
$ips = $item->{$property['property']};

if (!is_array($ips))
{
// Tokenize an array of content and add it to the database.
foreach ($item->$property as $ip)
{
/*
* If the group is path, we need to a few extra processing
* steps to strip the extension and convert slashes and dashes
* to spaces.
*/
if ($group === static::PATH_CONTEXT)
{
$ip = JFile::stripExt($ip);
$ip = str_replace(array('/', '-'), ' ', $ip);
}

// Tokenize a string of content and add it to the database.
$count += $this->tokenizeToDb($ip, $group, $item->language, $format);

// Check if we're approaching the memory limit of the token table.
if ($count > static::$state->options->get('memory_table_limit', 30000))
{
$this->toggleTables(false);
}
}
$ips = [$ips];
}
else

// Tokenize an array of content and add it to the database.
foreach ($ips as $ip)
{
/*
* If the group is path, we need to a few extra processing
Expand All @@ -199,13 +180,12 @@ public function index($item, $format = 'html')
*/
if ($group === static::PATH_CONTEXT)
{
$item->$property = JFile::stripExt($item->$property);
$item->$property = str_replace('/', ' ', $item->$property);
$item->$property = str_replace('-', ' ', $item->$property);
$ip = JFile::stripExt($ip);
$ip = str_replace(array('/', '-'), ' ', $ip);
}

// Tokenize a string of content and add it to the database.
$count += $this->tokenizeToDb($item->$property, $group, $item->language, $format);
$count += $this->tokenizeToDb($ip, $group, $item->language, $property['format']);

// Check if we're approaching the memory limit of the token table.
if ($count > static::$state->options->get('memory_table_limit', 30000))
Expand Down Expand Up @@ -240,7 +220,7 @@ public function index($item, $format = 'html')
$node->id = $nodeId;

// Tokenize the node title and add them to the database.
$count += $this->tokenizeToDb($node->title, static::META_CONTEXT, $item->language, $format);
$count += $this->tokenizeToDb($node->title, static::META_CONTEXT, $item->language, 'txt');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,14 +20,13 @@ class FinderIndexerDriverPostgresql extends FinderIndexer
* Method to index a content item.
*
* @param FinderIndexerResult $item The content item to index.
* @param string $format The format of the content. [optional]
*
* @return integer The ID of the record in the links table.
*
* @since 3.0
* @throws Exception on database error.
*/
public function index($item, $format = 'html')
public function index($item)
{
// Mark beforeIndexing in the profiler.
static::$profiler ? static::$profiler->mark('beforeIndexing') : null;
Expand Down Expand Up @@ -150,39 +149,21 @@ public function index($item, $format = 'html')
foreach ($properties as $property)
{
// Check if the property exists in the item.
if (empty($item->$property))
if (empty($item->{$property['property']}))
{
continue;
}

// Tokenize the property.
if (is_array($item->$property))
$ips = $item->{$property['property']};

if (!is_array($ips))
{
// Tokenize an array of content and add it to the database.
foreach ($item->$property as $ip)
{
/*
* If the group is path, we need to a few extra processing
* steps to strip the extension and convert slashes and dashes
* to spaces.
*/
if ($group === static::PATH_CONTEXT)
{
$ip = JFile::stripExt($ip);
$ip = str_replace(array('/', '-'), ' ', $ip);
}

// Tokenize a string of content and add it to the database.
$count += $this->tokenizeToDb($ip, $group, $item->language, $format);

// Check if we're approaching the memory limit of the token table.
if ($count > static::$state->options->get('memory_table_limit', 30000))
{
$this->toggleTables(false);
}
}
$ips = [$ips];
}
else

// Tokenize an array of content and add it to the database.
foreach ($ips as $ip)
{
/*
* If the group is path, we need to a few extra processing
Expand All @@ -191,13 +172,12 @@ public function index($item, $format = 'html')
*/
if ($group === static::PATH_CONTEXT)
{
$item->$property = JFile::stripExt($item->$property);
$item->$property = str_replace('/', ' ', $item->$property);
$item->$property = str_replace('-', ' ', $item->$property);
$ip = JFile::stripExt($ip);
$ip = str_replace(array('/', '-'), ' ', $ip);
}

// Tokenize a string of content and add it to the database.
$count += $this->tokenizeToDb($item->$property, $group, $item->language, $format);
$count += $this->tokenizeToDb($ip, $group, $item->language, $property['format']);

// Check if we're approaching the memory limit of the token table.
if ($count > static::$state->options->get('memory_table_limit', 30000))
Expand Down Expand Up @@ -232,7 +212,7 @@ public function index($item, $format = 'html')
$node->id = $nodeId;

// Tokenize the node title and add them to the database.
$count += $this->tokenizeToDb($node->title, static::META_CONTEXT, $item->language, $format);
$count += $this->tokenizeToDb($node->title, static::META_CONTEXT, $item->language, 'txt');
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -264,14 +264,13 @@ public static function resetState()
* Method to index a content item.
*
* @param FinderIndexerResult $item The content item to index.
* @param string $format The format of the content. [optional]
*
* @return integer The ID of the record in the links table.
*
* @since 2.5
* @throws Exception on database error.
*/
abstract public function index($item, $format = 'html');
abstract public function index($item);

/**
* Method to remove a link from the index.
Expand Down
46 changes: 25 additions & 21 deletions administrator/components/com_finder/helpers/indexer/result.php
Original file line number Diff line number Diff line change
Expand Up @@ -40,11 +40,21 @@ class FinderIndexerResult implements Serializable
* @since 2.5
*/
protected $instructions = array(
FinderIndexer::TITLE_CONTEXT => array('title', 'subtitle', 'id'),
FinderIndexer::TEXT_CONTEXT => array('summary', 'body'),
FinderIndexer::META_CONTEXT => array('meta', 'list_price', 'sale_price'),
FinderIndexer::PATH_CONTEXT => array('path', 'alias'),
FinderIndexer::MISC_CONTEXT => array('comments'),
FinderIndexer::TITLE_CONTEXT => [
['property' => 'title', 'format' => 'txt'],
['property' => 'subtitle', 'format' => 'txt'],
['property' => 'id', 'format' => 'txt']],
FinderIndexer::TEXT_CONTEXT => [
['property' => 'summary', 'format' => 'html'],
['property' => 'body', 'format' => 'html']],
FinderIndexer::META_CONTEXT => [
['property' => 'meta', 'format' => 'txt'],
['property' => 'list_price', 'format' => 'txt'],
['property' => 'sale_price', 'format' => 'txt']],
FinderIndexer::PATH_CONTEXT => [
['property' => 'path', 'format' => 'txt'],
['property' => 'alias', 'format' => 'txt']],
FinderIndexer::MISC_CONTEXT => [['property' => 'comments', 'format' => 'txt']]
);

/**
Expand Down Expand Up @@ -317,19 +327,20 @@ public function getInstructions()
*
* @param string $group The group to associate the property with.
* @param string $property The property to process.
* @param string $format The format of the property.
*
* @return void
*
* @since 2.5
*/
public function addInstruction($group, $property)
public function addInstruction($group, $property, $format = 'txt')
{
// Check if the group exists. We can't add instructions for unknown groups.
// Check if the property exists in the group.
if (array_key_exists($group, $this->instructions) && !in_array($property, $this->instructions[$group], true))
if (array_key_exists($group, $this->instructions) && !isset($this->instructions[$group][$property]))
{
// Add the property to the group.
$this->instructions[$group][] = $property;
$this->instructions[$group][$property] = ['property' => $property, 'format' => $format];
}
}

Expand All @@ -348,14 +359,7 @@ public function removeInstruction($group, $property)
// Check if the group exists. We can't remove instructions for unknown groups.
if (array_key_exists($group, $this->instructions))
{
// Search for the property in the group.
$key = array_search($property, $this->instructions[$group]);

// If the property was found, remove it.
if ($key !== false)
{
unset($this->instructions[$group][$key]);
}
unset($this->instructions[$group][$property]);
}
}

Expand Down Expand Up @@ -457,9 +461,9 @@ public function setLanguage()

/**
* Helper function to serialise the data of a FinderIndexerResult object
*
*
* @return string The serialised data
*
*
* @since 4.0.0
*/
public function serialize()
Expand Down Expand Up @@ -512,11 +516,11 @@ public function serialize()

/**
* Helper function to unserialise the data for this object
*
*
* @param string $serialized Serialised data to unserialise
*
*
* @return void
*
*
* @since 4.0.0
*/
public function unserialize($serialized)
Expand Down

0 comments on commit 9d8ae45

Please sign in to comment.