Skip to content

Commit

Permalink
some bugfixes
Browse files Browse the repository at this point in the history
  • Loading branch information
Marc Neuhaus committed May 16, 2017
1 parent 7e0ac5b commit 4dbc97e
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 11 deletions.
2 changes: 1 addition & 1 deletion src/Adapter/IndexAdapterInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@

interface IndexAdapterInterface
{
public function addObject($object, $objectId, $indexName = null);
public function addObject($object, $objectId);

public function getFacet($configuration);
}
10 changes: 5 additions & 5 deletions src/Adapter/MySQLAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ public function __construct($configuration)
));
}

public function addObject($object, $objectId, $indexName = null)
public function addObject($object, $objectId)
{
$id = $this->getObject($objectId, serialize($object), $indexName);
$id = $this->getObject($objectId, serialize($object));
$this->connection->query(sprintf('DELETE FROM %scontents WHERE object = "%s"',
$this->configuration['table_prefix'], $id));

Expand Down Expand Up @@ -116,7 +116,7 @@ protected function insertContent($id, $key, $value)
$query->execute();
}

public function getObject($objectId, $data, $indexName)
public function getObject($objectId, $data)
{
$query = sprintf('SELECT id FROM %sobjects WHERE objectId = "%s"', $this->configuration['table_prefix'],
$objectId);
Expand All @@ -131,7 +131,7 @@ public function getObject($objectId, $data, $indexName)
',
$this->configuration['table_prefix']
));
$query->bind_param("siis", $data, $timestamp, $row['id'], $indexName);
$query->bind_param("siis", $data, $timestamp, $row['id'], $this->configuration['indexName']);
$query->execute();

return intval($row['id']);
Expand All @@ -149,7 +149,7 @@ public function getObject($objectId, $data, $indexName)
$query->bind_param(
"sssii",
$objectId,
$indexName,
$this->configuration['indexName'],
$data,
$timestamp,
$timestamp
Expand Down
4 changes: 2 additions & 2 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ public function __construct($configuration) {
$this->adapter = new $configuration['adapter']($configuration);
}

public function addObject($object, $objectId, $indexName = null) {
$this->adapter->addObject($object, $objectId, $indexName);
public function addObject($object, $objectId) {
$this->adapter->addObject($object, $objectId);
}

public function search($query, $options = array()) {
Expand Down
6 changes: 3 additions & 3 deletions src/SearchWordHighlighter.php
Original file line number Diff line number Diff line change
Expand Up @@ -115,7 +115,7 @@ public function cutBeforeMatch($content, $words)
$contentWords = preg_split('/[\s]/s', trim($content));
$word = reset($words);
foreach ($contentWords as $key => $contentWord) {
similar_text(strtolower(trim($contentWord)), strtolower(trim($word)), $match);
similar_text(mb_strtolower(trim($contentWord)), mb_strtolower(trim($word)), $match);
if ($match > 80) {
// if the there are less words before the first search word, we can
// break here, because cutting before the first word makes no sense
Expand All @@ -124,11 +124,11 @@ public function cutBeforeMatch($content, $words)
}

// look for the position of the first search word
$startPosition = strpos($content, $contentWord);
$startPosition = mb_strpos($content, $contentWord);

for ($i = 1; $i <= $this->wordsBeforeMatch; $i++) {
if (isset($contentWords[$key - $i])) {
$startPosition -= strlen($contentWords[$key - $i]) + 1;
$startPosition -= mb_strlen($contentWords[$key - $i]) + 1;
}
}
$content = $this->prefix . trim(substr($content, $startPosition));
Expand Down
10 changes: 10 additions & 0 deletions tests/Unit/SearchWordHighlighterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,16 @@ public function getSomeHighlightingTestValues()
'wordsBeforeMatch' => 3,
'expecation' => '...elit. Accusamus animi <b>deleniti</b> dolore esseeveniet...',
),
array(
'string' => 'Lorem ipsum TÜV sit amet, consectetur adipisicing',
'words' => "tüv",
'wrap' => '<b>|</b>',
'crop' => 6,
'prefix' => '...',
'suffix' => '...',
'wordsBeforeMatch' => 3,
'expecation' => 'Lorem ipsum <b>TÜV</b> sit amet, consectetur...',
),
);
}
}

0 comments on commit 4dbc97e

Please sign in to comment.