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

- Fix : Ammélioration des recherches pour les organisations

parent 7097bfde
Loading
Loading
Loading
Loading
Loading
+1 −1
Original line number Diff line number Diff line
@@ -145,7 +145,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        try {
            $organizations = $this->getOrganizationService()->getOrganizationsSearchPaged($search, $page, $filter);
        } catch (BadRequest400Exception $e) {
            $error = _("Expression de recherche incorrecte");
            $error = _("Expression de recherche incorrecte") . ' : ' . $e->getMessage();
        }


+24 −2
Original line number Diff line number Diff line
@@ -395,11 +395,32 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana

        if( $search != "" ){
            $ids = $this->search($search, true);
           // var_dump($ids); die();

            $sortSize = 25;

            // ORDER BY de LREM
            // Permet de forcer le trie dans l'ordre des IDs fournit par Elastic Search
            if( count($ids) > 1 ){
                $selectHidden = "(CASE ";
                $i = 0;
                foreach ($ids as $id) {
                    $selectHidden .= " WHEN o.id = $id THEN $i ";
                    $i++;
                    if( $i > $sortSize ){
                        break;
                    }
                }
                $selectHidden .= " ELSE $i END) AS HIDDEN ORD";
                $qb->addSelect($selectHidden);
                $qb->orderBy('ORD', 'ASC');
            }

            $qb->where('o.id IN(:ids)')->setParameter('ids', $ids);
        } else {
            $qb->addOrderBy('o.dateEnd', 'DESC')->addOrderBy('o.dateUpdated', 'DESC');
        }

        //$qb->addOrderBy('o.dateEnd', 'DESC')->addOrderBy('o.dateUpdated', 'DESC');
        //

        // -------------------------------------------------------------------------------------------------------------
        // FILTRE sur les types d'organisations
@@ -493,6 +514,7 @@ class OrganizationService implements UseOscarConfigurationService, UseEntityMana
            $ids = $strategy->search($search);
            if( $justIds == true )
                return $ids;

            return $this->getOrganizationsByIds($ids);
        } else {
            return $this->getSearchNativeQuery($search, [])->getQuery()->getResult();
+54 −2
Original line number Diff line number Diff line
@@ -173,6 +173,7 @@ class OrganizationElasticSearch implements OrganizationSearchStrategy
            'city' => $organization->getCity(),
            'country' => $organization->getCountry(),
            'zipcode' => $organization->getZipCode(),
            'description' => $organization->getDescription(),
//            'address1' => $organization->getStreet1(),
//            'address2' => $organization->getStreet2(),
//            'address3' => $organization->getStreet3(),
@@ -191,23 +192,74 @@ class OrganizationElasticSearch implements OrganizationSearchStrategy
            'type' => $this->getType(),
            'body' => [
                'size' => 10000,


                "query" => [
                    'query_string' => [
                        'fields' => [ 'code^3','shortname^4', 'fullname^8','description','email',
                            'city', 'siret', 'country', 'connectors', 'zipcode', 'persons'],
                        'query' => $search,

                    ]
//                    "bool" => [
//                        "should" => [
//                            [ "match" => [
//                                "code" => [
//                                    "query" => "$search",
//                                    "boost" => 1
//                                ]
//                            ]],
//                            [ "match" => [
//                                "shortname" => [
//                                    "query" => "$search",
//                                    "boost" => 10
//                                ]
//                            ]],
//                            [ "match" => [
//                                "fullname" => [
//                                    "query" => "$search",
//                                    "boost" => 5
//                                ]
//                            ]],
//                        ]
//                    ]
                ]


                /* OFF
                'query' => [
                    'query_string' => [
                        'fields' => [ 'code','shortname^7', 'fullname^9','email', 'city', 'siret', 'country', 'connectors', 'zipcode', 'persons'],
                        "search_fields" => [
                            "shortname" => [
                                "weight" => 10
                            ],
                            "code" => [
                                "weight" => 2
                            ],
                            "fullname" => [
                                "weight" => 2
                            ],
                        ],
                        'query' => $search,
                        'use_dis_max' => true
                    ],
                ]
                ]
                /******/
            ]
        ];

        $response = $this->getClient()->search($params);
        $ids = [];

        //echo "<pre>";
        if ($response && $response['hits'] && $response['hits']['total'] > 0) {
            foreach ($response['hits']['hits'] as $hit) {
        //        echo $hit['_id'] . "\t " . $hit['_score'] . "- " . $hit['_source']['fullname'] ."\n";
                $ids[] = $hit["_id"];
            }
        }
        //echo "</pre>";

        return $ids;
    }