@@ -547,36 +547,15 @@ protected function initialize()
547
547
foreach ($ this ->mappings as $ indexName => $ indexProperties ) {
548
548
$ indexName = 'Qubit ' .sfInflector::camelize ($ indexName );
549
549
$ prefixedIndexName = $ this ->config ['index ' ]['name ' ].'_ ' .strtolower ($ indexName );
550
- $ this ->index ->addIndex ($ indexName ,
551
- $ this ->client ->getIndex ($ prefixedIndexName )
552
- );
553
- }
550
+ $ index = $ this ->client ->getIndex ($ prefixedIndexName );
551
+ $ this ->index ->addIndex ($ indexName , $ index );
554
552
555
- foreach ($ this ->index ->getIndices () as $ indexType => $ index ) {
556
553
try {
557
554
$ index ->open ();
558
555
} catch (Exception $ e ) {
559
556
// If the index has not been initialized, create it
560
557
if ($ e instanceof \Elastica \Exception \ResponseException) {
561
- // Based on the markdown_enabled setting, add a new filter to strip Markdown tags
562
- if (
563
- sfConfig::get ('app_markdown_enabled ' , true )
564
- && isset ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['char_filter ' ]['strip_md ' ])
565
- ) {
566
- foreach ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ] as $ key => $ analyzer ) {
567
- $ filters = ['strip_md ' ];
568
-
569
- if ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ]) {
570
- $ filters = array_merge ($ filters , $ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ]);
571
- }
572
-
573
- if (sfConfig::get ('app_diacritics ' )) {
574
- $ filters = array_merge ($ filters , ['diacritics_lowercase ' ]);
575
- }
576
-
577
- $ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ] = $ filters ;
578
- }
579
- }
558
+ $ this ->configureFilters ();
580
559
581
560
// In ES 7.x if the mapping type is updated to a dummy type,
582
561
// this may need to include a param for include_type_name
@@ -588,36 +567,53 @@ protected function initialize()
588
567
);
589
568
}
590
569
591
- // Iterate over types (actor, informationobject, ...)
592
- foreach ($ this ->mappings as $ indexName => $ indexProperties ) {
593
- $ indexName = 'Qubit ' .sfInflector::camelize ($ indexName );
570
+ // Define mapping in elasticsearch
571
+ $ mapping = new \Elastica \Type \Mapping ();
594
572
595
- if ($ indexType != $ indexName ) {
596
- continue ;
597
- }
573
+ // Setting a dummy type since it is required in ES 6.x
574
+ // but it can be removed in 7.x when it becomes optional
575
+ $ mapping ->setType ($ index ->getType (self ::ES_TYPE ));
576
+ $ mapping ->setProperties ($ indexProperties ['properties ' ]);
598
577
599
- // Define mapping in elasticsearch
600
- $ mapping = new \Elastica \Type \Mapping ();
578
+ // Parse other parameters
579
+ unset($ this ->mapping [$ indexName ]->indexProperties ['properties ' ]);
580
+ foreach ($ this ->mapping [$ indexName ]->indexProperties as $ key => $ value ) {
581
+ $ mapping ->setParam ($ key , $ value );
582
+ }
601
583
602
- // Setting a dummy type since it is required in ES 6.x
603
- // but it can be removed in 7.x when it becomes optional
604
- $ mapping ->setType ($ index ->getType (self ::ES_TYPE ));
605
- $ mapping ->setProperties ($ indexProperties ['properties ' ]);
584
+ $ this ->log (sprintf ('Defining mapping for index %s... ' , $ prefixedIndexName ));
606
585
607
- // Parse other parameters
608
- unset($ this ->mapping [$ indexName ]->indexProperties ['properties ' ]);
609
- foreach ($ this ->mapping [$ indexName ]->indexProperties as $ key => $ value ) {
610
- $ mapping ->setParam ($ key , $ value );
611
- }
586
+ // In ES 7.x this should be changed to:
587
+ // $mapping->send($index, [ 'include_type_name' => false ])
588
+ // which can be removed in 8.x since that is the default behaviour
589
+ // and will have be removed by 9.x when it is discontinued
590
+ $ mapping ->send ();
591
+ }
592
+ }
593
+ }
612
594
613
- $ this ->log (sprintf ('Defining mapping %s... ' , $ indexName ));
595
+ /**
596
+ * Set filter configuration params based on markdown settings.
597
+ */
598
+ private function configureFilters ()
599
+ {
600
+ // Based on markdown_enabled setting, add a new filter to strip Markdown tags
601
+ if (
602
+ sfConfig::get ('app_markdown_enabled ' , true )
603
+ && isset ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['char_filter ' ]['strip_md ' ])
604
+ ) {
605
+ foreach ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ] as $ key => $ analyzer ) {
606
+ $ filters = ['strip_md ' ];
607
+
608
+ if ($ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ]) {
609
+ $ filters = array_merge ($ filters , $ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ]);
610
+ }
614
611
615
- // In ES 7.x this should be changed to:
616
- // $mapping->send($index, [ 'include_type_name' => false ])
617
- // which can be removed in 8.x since that is the default behaviour
618
- // and will have be removed by 9.x when it is discontinued
619
- $ mapping ->send ();
612
+ if (sfConfig::get ('app_diacritics ' )) {
613
+ $ filters = array_merge ($ filters , ['diacritics_lowercase ' ]);
620
614
}
615
+
616
+ $ this ->config ['index ' ]['configuration ' ]['analysis ' ]['analyzer ' ][$ key ]['char_filter ' ] = $ filters ;
621
617
}
622
618
}
623
619
}
0 commit comments