-
Notifications
You must be signed in to change notification settings - Fork 188
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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; | ||
|
@@ -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) { | ||
$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([]); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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, There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @Numkil, You mean exception? There was a problem hiding this comment. Choose a reason for hiding this commentThe 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); | ||
} | ||
|
@@ -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(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -77,6 +77,8 @@ public function getClient() | |
*/ | ||
public function createDocument($uid, $document, $indexName = '', $indexType = '') | ||
{ | ||
$indexName = strtolower($indexName); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why are you doing strtolower here? |
||
|
||
return $this->getActiveProvider()->createDocument( | ||
$uid, | ||
$document, | ||
|
@@ -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, | ||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
@@ -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); | ||
} | ||
|
||
|
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
good point