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

- Ajout de l'option --mapping à la commande activity:search permettant de voir les champs indéxés

 - Suppression de la détection automatique des dates/long pour corriger une erreur d'indexation des numérotations personnalisés
parent b3d1566f
Loading
Loading
Loading
Loading
+16 −2
Original line number Diff line number Diff line
@@ -18,9 +18,8 @@ class OscarActivitySearchCommand extends OscarAdvancedCommandAbstract
{
    protected static $defaultName = OscarCommandAbstract::COMMAND_ACTIVITY_SEARCH;


    const ARG_SEARCH = 'search';

    const OPT_MAP = 'mapping';
    const OPT_PER = 'members';
    const OPT_ORG = 'organizations';
    const OPT_SRT = 'sort';
@@ -54,6 +53,9 @@ class OscarActivitySearchCommand extends OscarAdvancedCommandAbstract
            ->addOption(self::OPT_MUT, 'm',
                        InputOption::VALUE_NONE,
                        "N'affiche pas les activités")
            ->addOption(self::OPT_MAP, 'g',
                        InputOption::VALUE_NONE,
                        "Afficher le mappings")

            ->addArgument(self::ARG_SEARCH)
        ;
@@ -68,7 +70,19 @@ class OscarActivitySearchCommand extends OscarAdvancedCommandAbstract
        $direction = $input->getOption(self::OPT_DIR);
        $filtersOption = $input->getOption(self::OPT_FIL);
        $muted = $input->getOption(self::OPT_MUT);
        $mapping = $input->getOption(self::OPT_MAP);
        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();

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

        $this->getIO()->title("Recherche '$search' (sort: $sort - dir: $direction)");
+0 −7
Original line number Diff line number Diff line
@@ -137,13 +137,6 @@ class ElasticActivitySearch extends ElasticSearchEngine implements IActivitySear
            $words = explode(" ", $search);
            $wordsNbr = count($words);
            $andQuery = implode(" AND ", $words);

            // TEST d'approximation
//            $wordsUpdated = [];
//            foreach ($words as $word) {
//                $lng = (int)(strlen($word) / 4);
//                $wordsUpdated[] = $word . ($lng > 0 ? "~$lng" : "");
//            }
        }


+26 −4
Original line number Diff line number Diff line
@@ -48,7 +48,7 @@ abstract class ElasticSearchEngine
     * @return Client
     * @throws OscarException
     */
    protected function getClient(): Client
    public function getClient(): Client
    {
        try {
            if ($this->elasticSearchClient === null) {
@@ -56,6 +56,21 @@ abstract class ElasticSearchEngine
                    ->setHosts($this->getHosts())
                    ->build();
            }
            if( !$this->elasticSearchClient->indices()->exists(['index' => $this->getIndex()]) ){
                $this->loggerService->debug("INDEX CREATE " . $this->getIndex());
                $this->elasticSearchClient->indices()->create(
                    [
                        'index' => $this->getIndex(),
                        'body' => [
                            'mappings' => [
                                // Suppression de la détection des dates/nombres
                                'date_detection' => false,
                                'numeric_detection' => false,
                            ]
                        ]
                    ]
                );
            }
            return $this->elasticSearchClient;
        } catch (\Exception $exception) {
            $msg = "Création du client impossible";
@@ -64,6 +79,10 @@ abstract class ElasticSearchEngine
        }
    }

    public function getMapping() :array {
        return $this->getClient()->indices()->getMapping(['index' => $this->getIndex()]);
    }

    /**
     * @param mixed $object
     * @return callable|array
@@ -72,6 +91,7 @@ abstract class ElasticSearchEngine
    public function addItem(mixed $object): callable|array
    {
        $client = $this->getClient();
        $this->loggerService->debug("additem");

        try {
            $params = ['body' => []];
@@ -111,11 +131,13 @@ abstract class ElasticSearchEngine
        try {
            $i = 0;
            foreach ($items as $item) {
                $this->loggerService->debug(" + bulk " . $item->getId());
                $this->loggerService->debug(json_encode($this->getIndexableDatas($item)));
                $i++;
                $params['body'][] = [
                    'index' => [
                        '_index' => $this->getIndex(),
                        '_type'  => $this->getType(),
                        // '_type'  => $this->getType(),
                        '_id'    => $item->getId()
                    ]
                ];
@@ -156,7 +178,7 @@ abstract class ElasticSearchEngine

        $query = [
            'index' => $this->getIndex(),
            'type'  => $this->getType(),
            //'type'  => $this->getType(),
            'body'  => [
                'size'  => $limit,
                "query" => $this->getFieldsSearchedWeighted($search)
@@ -246,7 +268,7 @@ abstract class ElasticSearchEngine
    {
        $params = [
            'index' => $this->getIndex(),
            'type'  => $this->getType(),
//            'type'  => $this->getType(),
            'id'    => $item->getId(),
            'body'  => [
                'doc' => $this->getIndexableDatas($item)
+7 −1
Original line number Diff line number Diff line
@@ -9,6 +9,7 @@
namespace Oscar\Strategy\Search;


use Elasticsearch\Client;
use Oscar\Entity\Activity;

interface IActivitySearchStrategy extends ISearchStrategyCore
@@ -18,10 +19,15 @@ interface IActivitySearchStrategy extends ISearchStrategyCore
     * Ajoute une activité au moteur de recherche.
     *
     * @param Activity $activity
     * @return mixed
     * @return callable|array
     */
    public function addActivity(Activity $activity): callable|array;

    /**
     * @return Client
     */
    public function getClient(): Client;

    /**
     * Recherche dans les projets.
     *