Commit 823bb201 authored by Stephane Bouvry's avatar Stephane Bouvry
Browse files

Recherche des activité v2 en cours (non-fonctionnel)

parent 21b61fef
Loading
Loading
Loading
Loading
Loading
+1 −0
Original line number Diff line number Diff line
@@ -151,6 +151,7 @@ return array(
                [
                    'controller' => 'Activity',
                    'action' => [
                        'advancedsearch2',
                        'show',
                        'show2',
                        'edit',
+8 −1
Original line number Diff line number Diff line
@@ -804,7 +804,7 @@ organization:
    may_terminate: true
    defaults:
      controller: Organization
      action: index
      action: index2
  may_terminate: true
  child_routes:

@@ -1020,6 +1020,13 @@ contract:
        defaults:
          action: advancedSearch

    advancedsearch2:
      type: segment
      options:
        route: /advancedsearch2
        defaults:
          action: advancedSearch2

    api:
      type: segment
      options:
+2 −1
Original line number Diff line number Diff line
@@ -112,6 +112,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
    {
        $types = $this->getOrganizationService()->getOrganizationTypesSelect();


        $sorting = [
            'hit'         => 'Pertinence (recherche textuelle)',
            'shortName'   => 'Nom court',
@@ -140,7 +141,7 @@ class OrganizationController extends AbstractOscarController implements UseOrgan
        }

        if( $this->isAjax() || $this->params()->fromQuery('f') === 'json'){
            //$this->getOscarUserContextService()->check("UNDEFINED_PRIVIEGE");
            $this->getLoggerService()->debug("Search organization");
            try {
                $page = (int)$this->params()->fromQuery('page', 1);
                $search = $this->params()->fromQuery('q', '');
+17 −0
Original line number Diff line number Diff line
@@ -2776,6 +2776,23 @@ class ProjectGrantController extends AbstractOscarController implements UseNotif
        return $this->applyAdvancedSearch();
    }

    public function advancedSearch2Action(): array|ViewModel
    {
        if( $this->isAjax() || $this->params()->fromQuery('f') === 'json' ){
            $datas = [];
            $params = [
                    'q' => $this->params()->fromQuery('q', ''),
                    'page' => $this->params()->fromQuery('page', 1),
                    'rbp' => $this->params()->fromQuery('rbp', 20),
                    'sort' => $this->params()->fromQuery('sort', 'hit'),
                    'direction' => $this->params()->fromQuery('direction', 'ASC'),
            ];
            $response = new JsonModel($this->getProjectGrantService()->search2($params));
            return $response;
        }
        return [];
    }

    /**
     * Liste des activités de recherche.
     */
+30 −1
Original line number Diff line number Diff line
@@ -1202,6 +1202,8 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        $this->getEntityManager()->flush($entity);
    }



    protected function debug__displayIds(array $ids)
    {
        echo " = ";
@@ -2147,6 +2149,26 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi
        $this->getSearchEngineStrategy()->addActivity($activity);
    }

    public function search2(array $params)
    {
        /** Construction de la requête **/
        $body = [];

        $result = $this->getSearchEngineStrategy()->searchRaw($params['q'], $limit = 1000, $body);

        $total = $result['hits']['total']['value'];
        $datas = [];
        foreach ($result['hits']['hits'] as $item) {
            $datas[] = $item['_source'];
        }

        return [
            'total' => $total,
            'activities' => $datas,
            'query' => $body
        ];
    }

    /**
     * Retourne les jalons de l'activité.
     *
@@ -2160,7 +2182,14 @@ class ProjectGrantService implements UseGearmanJobLauncherService, UseOscarConfi

    public function searchIndex_rebuild()
    {
        $activities = $this->getEntityManager()->getRepository(Activity::class)->findAll();
        //$activities = $this->getEntityManager()->getRepository(Activity::class)->findAll();
        $activities = $this->getEntityManager()->getRepository(Activity::class)->findBy(
            [],
            ['dateUpdated' => 'DESC'],
            10,
            0
        );

        $this->getLoggerService()->info('[elasic] Reindex ' . count($activities) . ' activitie(s)');
        return $this->getSearchEngineStrategy()->rebuildIndex($activities);
    }
Loading