Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[NodeSearchBundle][SearchBundle] Multi domain/language search population fix #1635

Merged
merged 4 commits into from
Nov 18, 2017
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,6 @@
use Kunstmaan\NodeBundle\Helper\RenderContext;
use Kunstmaan\NodeSearchBundle\Event\IndexNodeEvent;
use Kunstmaan\NodeSearchBundle\Helper\IndexablePagePartsService;
use Kunstmaan\NodeSearchBundle\Helper\SearchBoostInterface;
use Kunstmaan\NodeSearchBundle\Helper\SearchViewTemplateInterface;
use Kunstmaan\PagePartBundle\Helper\HasPagePartsInterface;
use Kunstmaan\SearchBundle\Configuration\SearchConfigurationInterface;
Expand Down Expand Up @@ -137,14 +136,23 @@ public function createIndex()
);

foreach ($this->locales as $locale) {
$localeAnalysis = clone($analysis);
$language = $this->analyzerLanguages[$locale]['analyzer'];
// Multilanguage check
if (count(preg_grep('/[a-z]{2}_?+[a-zA-Z]{2}/', [$locale])) > 0) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why not use preg_match instead?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

good point

$locale = strtolower($locale);
}

//build new index
// Build new index
$index = $this->searchProvider->createIndex($this->indexName . '_' . $locale);

//create index with analysis
$this->setAnalysis($index, $localeAnalysis->setupLanguage($language));
if (array_key_exists($locale, $this->analyzerLanguages)) {
$localeAnalysis = clone $analysis;
$language = $this->analyzerLanguages[$locale]['analyzer'];

// Create index with analysis
$this->setAnalysis($index, $localeAnalysis->setupLanguage($language));
} else {
$index->create([]);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would prefer a very clear warning happening here that says something like,
"hey we did not crash but something is wrong here, we could not set up any analysis for this language".

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@Numkil, You mean exception?

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the best course of action is to somehow show a warning in the command output. Otherwise it will not be clear for developers why their search might not be behaving as expected without manually checking the index metadata. If a simple message is shown in the console command output then at least users will immediately know that they forgot to define an analyzer language

}

$this->setMapping($index, $locale);
}
Expand Down Expand Up @@ -334,7 +342,7 @@ protected function createDefaultSearchFieldsMapping(Index $index, $lang = 'en')
* @param Index $index
* @param string $lang
*/
protected function setMapping(Index $index, $lang = 'en')
protected function setMapping(Index $index, $lang='en')
{
$mapping = $this->createDefaultSearchFieldsMapping($index, $lang);
$mapping->send();
Expand Down
12 changes: 12 additions & 0 deletions src/Kunstmaan/SearchBundle/Search/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ public function getClient()
*/
public function createDocument($uid, $document, $indexName = '', $indexType = '')
{
$indexName = strtolower($indexName);
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why are you doing strtolower here?


return $this->getActiveProvider()->createDocument(
$uid,
$document,
Expand All @@ -90,6 +92,8 @@ public function createDocument($uid, $document, $indexName = '', $indexType = ''
*/
public function addDocument($uid, $document, $indexType, $indexName)
{
$indexName = strtolower($indexName);

return $this->getActiveProvider()->addDocument(
$this->indexNamePrefix . $indexName,
$indexType,
Expand All @@ -103,6 +107,8 @@ public function addDocument($uid, $document, $indexType, $indexName)
*/
public function addDocuments($documents, $indexName = '', $indexType = '')
{
$indexName = strtolower($indexName);

return $this->getActiveProvider()->addDocuments($documents, $indexName, $indexType);
}

Expand All @@ -111,6 +117,8 @@ public function addDocuments($documents, $indexName = '', $indexType = '')
*/
public function deleteDocument($indexName, $indexType, $uid)
{
$indexName = strtolower($indexName);

return $this->getActiveProvider()->deleteDocument($this->indexNamePrefix . $indexName, $indexType, $uid);
}

Expand All @@ -119,6 +127,8 @@ public function deleteDocument($indexName, $indexType, $uid)
*/
public function deleteDocuments($indexName, $indexType, array $ids)
{
$indexName = strtolower($indexName);

return $this->getActiveProvider()->deleteDocuments($this->indexNamePrefix . $indexName, $indexType, $ids);
}

Expand All @@ -127,6 +137,8 @@ public function deleteDocuments($indexName, $indexType, array $ids)
*/
public function deleteIndex($indexName)
{
$indexName = strtolower($indexName);

return $this->getActiveProvider()->deleteIndex($this->indexNamePrefix . $indexName);
}

Expand Down