10847-ESPlugin-changes.diff

Steve Breker, 06/23/2017 03:56 PM

Download (9.37 KB)

View differences:

plugins/arElasticSearchPlugin/config/search.yml
16 16
    port: 9200
17 17

  
18 18
    # This will write the JSON request in the file given
19
    # log: '/tmp/elastica.log'
19
    log: '/tmp/elastica.log'
20 20

  
21 21
  # elasticsearch options
22 22
  index:
plugins/arElasticSearchPlugin/lib/arElasticSearchPlugin.class.php
67 67
  /**
68 68
   * Minimum version of Elasticsearch supported
69 69
   */
70
  const MIN_VERSION = '1.3.0';
70
  const MIN_VERSION = '5.0.0';
71 71

  
72 72
  /**
73 73
   * Constructor
......
79 79
    $this->cache = QubitCache::getInstance();
80 80

  
81 81
    $this->config = arElasticSearchPluginConfiguration::$config;
82
file_put_contents('/tmp/eslog.txt', 'SBSBSB log ' . $this->config['log'] ."\n",  FILE_APPEND );
82 83
    $this->client = new \Elastica\Client($this->config['server']);
83 84

  
84 85
    // Verify the version running in the server
plugins/arElasticSearchPlugin/lib/arElasticSearchPluginQuery.class.php
36 36
  public function __construct($limit = 10, $skip = 0)
37 37
  {
38 38
    $this->query = new \Elastica\Query();
39
    $this->query->setLimit($limit);
39
    $this->query->setSize($limit);
40 40
    $this->query->setFrom($skip);
41 41

  
42 42
    $this->queryBool = new \Elastica\Query\BoolQuery;
43
    $this->filterBool = new \Elastica\Filter\BoolFilter;
43
    $this->filterBool = new \Elastica\Query\BoolQuery;
44
    // orig: filters are now query type
45
    //$this->filterBool = new \Elastica\Filter\BoolFilter;
46
    // this was first attempt: this is wrong:
47
    //$this->filterBool = new \Elastica\Aggregation\Filter('filterBool');
44 48
  }
45 49

  
46 50
  /**
......
57 61
    {
58 62
      if (!is_array($item))
59 63
      {
60
        $facet = new \Elastica\Facet\Terms($item);
64
        // facets become aggregations.
65
        $facet = new \Elastica\Aggregation\Terms($item);
61 66
        $facet->setField($item);
62 67
        $facet->setSize(10);
63 68

  
64
        $this->query->addFacet($facet);
69
        $this->query->addAggregation($facet);
65 70

  
66 71
        continue;
67 72
      }
......
69 74
      switch ($item['type'])
70 75
      {
71 76
        case 'range':
72
          $facet = new \Elastica\Facet\Range($name);
77
          $facet = new \Elastica\Aggregation\Range($name);
73 78
          $facet->setField($item['field']);
74 79
          $facet->addRange($item['from'], $item['to']);
75 80

  
76 81
          break;
77 82

  
78 83
        case 'term':
79
          $facet = new \Elastica\Facet\Terms($name);
84
        case 'query':
85
          $facet = new \Elastica\Aggregation\Terms($name);
80 86
          $facet->setField($item['field']);
81 87

  
82 88
          break;
83 89

  
84
        case 'query':
85
          $facet = new \Elastica\Facet\Query($name);
86
          $facet->setQuery(new \Elastica\Query\Term($item['field']));
90
        //case 'query':
91
          //$facet = new \Elastica\Aggregation\Terms($name);
92
          //$facet->setField($item['field']);
87 93

  
88
          break;
94
          //break;
95

  
96
        //case 'query':
97
          //$facet = new \Elastica\Facet\Query($name);
98
          //$facet->setQuery(new \Elastica\Query\Term($item['field']));
99

  
100
          //break;
89 101
      }
90 102

  
91 103
      // Sets the amount of terms to be returned
......
94 106
        $facet->setSize($item['size']);
95 107
      }
96 108

  
97
      $filter = new \Elastica\Filter\BoolFilter;
109
      // filters are now query type
110
      //$filter = new \Elastica\Filter\BoolFilter;
111
      // 1st incorrect attempt
112
      $filter = new \Elastica\Aggregation\Filter($name);
113
      //$filter = new \Elastica\Query\BoolQuery;
98 114

  
99 115
      // Sets a filter for this facet
100 116
      if (isset($item['filter']))
......
110 126
      // Apply facet filter if exists
111 127
      if (0 < count($filter->toArray()))
112 128
      {
113
        $facet->setFilter($filter);
129
        //$this->query->addFilter($filter);
130
        //$facet->setFilter($filter);
131
        //$facet->addAggregation($filter);  <-- UNCOMMENT
114 132
      }
115 133

  
116
      $this->query->addFacet($facet);
134
      $this->query->addAggregation($facet);
117 135
    }
118 136
  }
119 137

  
......
134 152
    if (isset($facets['languages']) && isset($params['languages']))
135 153
    {
136 154
      $this->filters['languages'] = $params['languages'];
137
      $term = new \Elastica\Filter\Term(array($facets['languages']['field'] => $params['languages']));
155
      $term = new \Elastica\Aggregation\Term(array($facets['languages']['field'] => $params['languages']));
138 156

  
139 157
      $this->filterBool->addMust($term);
140 158
    }
......
472 490
        {
473 491
          // Filtered query for documents without copyright status
474 492
          $queryAll = new \Elastica\Query\MatchAll();
475
          $filter = new \Elastica\Filter\Missing;
493
          $filter = new \Elastica\Query\Exists;
476 494
          $filter->setField('copyrightStatusId');
477
          $filteredQuery = new \Elastica\Query\Filtered($queryAll, $filter);
495
          $filterMustNot = new \Elastica\Query\BoolQuery;
496
          $filterMustNot->addMustNot($filter);
497
          $filteredQuery = new \Elastica\Query\Term($queryAll, $filterMustNot);
478 498

  
479 499
          // Query for unknown copyright status
480 500
          $query = new \Elastica\Query\Term;
......
511 531
        {
512 532
          case 'yes':
513 533
            $queryAll = new \Elastica\Query\MatchAll();
514
            $filter = new \Elastica\Filter\Exists('findingAid.status');
515
            $filteredQuery = new \Elastica\Query\Filtered($queryAll, $filter);
534
            $filter = new \Elastica\Query\Exists('findingAid.status');
535
            $filteredQuery = new \Elastica\Query\Term($queryAll, $filter);
516 536

  
517 537
            return $filteredQuery;
518 538

  
519 539
          case 'no':
520 540
            $queryAll = new \Elastica\Query\MatchAll();
521 541
            $filter = new \Elastica\Filter\Missing('findingAid.status');
522
            $filteredQuery = new \Elastica\Query\Filtered($queryAll, $filter);
542
            $filteredQuery = new \Elastica\Query\Term($queryAll, $filter);
523 543

  
524 544
            return $filteredQuery;
525 545

  
......
654 674
    {
655 675
      $this->query->setPostFilter($this->filterBool);
656 676
    }
657

  
677
sfContext::getInstance()->getLogger()->info('SBSBSB ' . json_encode($this->query->toArray()) );
658 678
    return $this->query;
659 679
  }
660 680
}
plugins/qbAclPlugin/lib/QubitAclSearch.class.php
163 163
   *
164 164
   * @param  \Elastica\Filter\BoolFilter $filterBool Search query object
165 165
   */
166
  public static function filterDrafts(\Elastica\Filter\BoolFilter $filterBool)
166
  public static function filterDrafts(\Elastica\Aggregation\Filter $filterBool)
167 167
  {
168 168
    // Filter out 'draft' items by repository
169 169
    $repositoryViewDrafts = QubitAcl::getRepositoryAccess('viewDraft');
......
172 172
      if (QubitAcl::DENY == $repositoryViewDrafts[0]['access'])
173 173
      {
174 174
        // Don't show *any* draft info objects
175
        $filter = new \Elastica\Filter\Term();
175
        $filter = new \Elastica\Query\Term();
176 176
        $filter->setTerm('publicationStatusId', QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID);
177 177

  
178
        $filterBool->addMust($filter);
178
        $filterBool->setFilter($filter);
179 179
      }
180 180
    }
181 181
    else
......
185 185
      // preceeding rules will be "ALLOW" rules)
186 186
      $globalRule = array_pop($repositoryViewDrafts);
187 187

  
188
      $filter = new \Elastica\Filter\BoolFilter;
188
      $filter = new \Elastica\Query\Bool;
189 189

  
190 190
      while ($repo = array_shift($repositoryViewDrafts))
191 191
      {
192
        $filter->addShould(new \Elastica\Filter\Term(array('repository.id' => (int)$repo['id'])));
192
        $filter->addShould(new \Elastica\Query\Term(array('repository.id' => (int)$repo['id'])));
193 193
      }
194 194

  
195
      $filter->addShould(new \Elastica\Filter\Term(array('publicationStatusId' => QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID)));
195
      $filter->addShould(new \Elastica\Query\Term(array('publicationStatusId' => QubitTerm::PUBLICATION_STATUS_PUBLISHED_ID)));
196 196

  
197 197
      // Does this ever happen in AtoM?
198 198
      if ($globalRule['access'] == QubitAcl::GRANT)
199 199
      {
200
        $filter = new \Elastica\Filter\BoolNot($filter);
200
        //$filter = new \Elastica\Query\Bool($filter);
201 201
      }
202 202

  
203
      $filterBool->addMust($filter);
203
      $filterBool->setFilter($filter);
204 204
    }
205 205
  }
206 206
}