Commit f37f96e1 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

- Ajout de l'option --mapping au commande organizations:search et...

 - Ajout de l'option --mapping au commande organizations:search et persons:search pour afficher le mapping
parent bfc28cb3
Loading
Loading
Loading
Loading
+1 −8
Original line number Diff line number Diff line
@@ -74,14 +74,7 @@ class OscarActivitySearchCommand extends OscarAdvancedCommandAbstract
        if( $mapping ){
            $map = $this->getProjectGrantService()->getSearchEngineStrategy()->getMapping();
            $output->write(json_encode($map, JSON_PRETTY_PRINT));
//
//            $params = ['format' => 'json'];
//
//            $indices = $map = $this->getProjectGrantService()->getSearchEngineStrategy()->getClient()->cat()->indices($params);
//            var_dump($indices);

            die();

            return self::SUCCESS;
        }
        $filters = $filtersOption != "" ? explode('|', $filtersOption) : [];

+17 −10
Original line number Diff line number Diff line
@@ -36,29 +36,36 @@ class OscarOrganizationsSearchCommand extends OscarCommandAbstract
    {
        $this
            ->setDescription("Recherche dans les organisations")
            ->addArgument("search", InputArgument::REQUIRED, "Expression à rechercher")
            ->addArgument("search", InputArgument::OPTIONAL, "Expression à rechercher")
            ->addOption("mapping", 'g',
                        InputOption::VALUE_NONE,
                        "Afficher le mappings")
        ;
    }

    protected function execute(InputInterface $input, OutputInterface $output)
    {
        $this->addOutputStyle($output);

        /** @var OscarUserContext $oscaruserContext */
        $oscaruserContext = $this->getServicemanager()->get(OscarUserContext::class);

        $io = new SymfonyStyle($input, $output);

        $io->title("Recherche dans les organisations");

        /** @var OscarConfigurationService $oscarConfig */
        $oscarConfig = $this->getServicemanager()->get(OscarConfigurationService::class);

        /** @var OrganizationService $organisationService */
        $organisationService = $this->getServicemanager()->get(OrganizationService::class);

        $mapping = $input->getOption("mapping");
        if( $mapping ){
            $map = $organisationService->getSearchEngineStrategy()->getMapping();
            $output->write(json_encode($map, JSON_PRETTY_PRINT));
            return self::SUCCESS;
        }

        $io->title("Recherche dans les organisations");

        try {
            $search = $input->getArgument('search');
            if( !$search ){
                $io->error("Précisez la recherche");
                return self::INVALID;
            }
            $organisations = $organisationService->search($search);
            /** @var Organization $organisation */
            foreach ($organisations as $organisation) {
+15 −1
Original line number Diff line number Diff line
@@ -34,7 +34,8 @@ class OscarPersonsSearchCommand extends OscarCommandAbstract
    {
        $this
            ->setDescription("Recherche dans l'index de recherche des personnes")
            ->addArgument('search', InputArgument::REQUIRED, 'Expression de recherche')
            ->addArgument('search', InputArgument::OPTIONAL, 'Expression de recherche')
            ->addOption("mapping", 'g',InputOption::VALUE_NONE,"Afficher le mappings")
        ;
    }

@@ -52,7 +53,20 @@ class OscarPersonsSearchCommand extends OscarCommandAbstract
        /** @var PersonService $personService */
        $personService = $this->getServicemanager()->get(PersonService::class);

        $mapping = $input->getOption("mapping");
        if( $mapping ){
            $map = $personService->getSearchEngineStrategy()->getMapping();
            $output->write(json_encode($map, JSON_PRETTY_PRINT));
            return self::SUCCESS;
        }

        try {
            $search = $input->getArgument('search');
            if( !$search ){
                $io->error("Précisez la recherche");
                return self::INVALID;
            }

            $ids = $personService->getSearchEngineStrategy()->search($search);
            if( count($ids) ){
                $persons = $personService->getPersonsByIds($ids);
+4 −5
Original line number Diff line number Diff line
@@ -121,7 +121,7 @@ abstract class ElasticSearchEngine
     */
    public function rebuildIndex(array $items): void
    {
        $this->loggerService->debug('[elasticsearch] Rebuilding index...');
        $this->loggerService->debug('[elasticsearch] Rebuilding index "'. $this->getIndex().'"...');
        try {
            $this->resetIndex();
        } catch (\Exception $exception) {
@@ -131,8 +131,7 @@ abstract class ElasticSearchEngine
        try {
            $i = 0;
            foreach ($items as $item) {
                $this->loggerService->debug(" + bulk " . $item->getId());
                $this->loggerService->debug(json_encode($this->getIndexableDatas($item)));
                $this->loggerService->debug(" + prepare " . $item->getId());
                $i++;
                $params['body'][] = [
                    'index' => [
@@ -146,6 +145,7 @@ abstract class ElasticSearchEngine

                // On envoie par paquet de 1000
                if ($i % 1000 == 0) {
                    $this->loggerService->debug(" + BULK ");
                    $responses = $this->getClient()->bulk($params);

                    // clean datas
@@ -155,6 +155,7 @@ abstract class ElasticSearchEngine
            }

            if (!empty($params['body'])) {
                $this->loggerService->debug(" + BULK ");
                $client->bulk($params);
            }
        } catch (\Exception $exception) {
@@ -253,7 +254,6 @@ abstract class ElasticSearchEngine
    {
        $params = [
            'index' => $this->getIndex(),
            'type'  => $this->getType(),
            'id'    => "$id"
        ];
        return $this->getClient()->delete($params);
@@ -268,7 +268,6 @@ abstract class ElasticSearchEngine
    {
        $params = [
            'index' => $this->getIndex(),
//            'type'  => $this->getType(),
            'id'    => $item->getId(),
            'body'  => [
                'doc' => $this->getIndexableDatas($item)
+1 −13
Original line number Diff line number Diff line
@@ -35,19 +35,7 @@ class PersonElasticSearch extends ElasticSearchEngine implements IPersonISearchS
     */
    public function add(Person $person):callable|array
    {
        $params = ['body' => []];

        $params['body'][] = [
            'index' => [
                '_index' => $this->getIndex(),
                '_type' => $this->getType(),
                '_id' => $person->getId(),
            ]
        ];

        $params['body'][] = $this->getIndexableDatas($person);

        return $this->getClient()->bulk($params);
        return $this->addItem($person);
    }

    public function getIndexableDatas(mixed $item) :array