Code Duplication    Length = 48-54 lines in 2 locations

eZ/Publish/Core/Search/Legacy/Content/Handler.php 2 locations

@@ 143-196 (lines=54) @@
140
     *
141
     * @return \eZ\Publish\API\Repository\Values\Content\Search\SearchResult
142
     */
143
    public function findContent(Query $query, array $languageFilter = array())
144
    {
145
        if (!isset($languageFilter['languages'])) {
146
            $languageFilter['languages'] = array();
147
        }
148
149
        if (!isset($languageFilter['useAlwaysAvailable'])) {
150
            $languageFilter['useAlwaysAvailable'] = true;
151
        }
152
153
        $start = microtime(true);
154
        $query->filter = $query->filter ?: new Criterion\MatchAll();
155
        $query->query = $query->query ?: new Criterion\MatchAll();
156
157
        if (count($query->facetBuilders)) {
158
            throw new NotImplementedException('Facets are not supported by the legacy search engine.');
159
        }
160
161
        // The legacy search does not know about scores, so that we just
162
        // combine the query with the filter
163
        $filter = new Criterion\LogicalAnd(array($query->query, $query->filter));
164
165
        $data = $this->gateway->find(
166
            $filter,
167
            $query->offset,
168
            $query->limit,
169
            $query->sortClauses,
170
            $languageFilter,
171
            $query->performCount
172
        );
173
174
        $result = new SearchResult();
175
        $result->time = microtime(true) - $start;
176
        $result->totalCount = $data['count'];
177
        $contentInfoList = $this->contentMapper->extractContentInfoFromRows(
178
            $data['rows'],
179
            '',
180
            'main_tree_'
181
        );
182
183
        foreach ($contentInfoList as $index => $contentInfo) {
184
            $searchHit = new SearchHit();
185
            $searchHit->valueObject = $contentInfo;
186
            $searchHit->matchedTranslation = $this->extractMatchedLanguage(
187
                $data['rows'][$index]['language_mask'],
188
                $data['rows'][$index]['initial_language_id'],
189
                $languageFilter
190
            );
191
192
            $result->searchHits[] = $searchHit;
193
        }
194
195
        return $result;
196
    }
197
198
    protected function extractMatchedLanguage($languageMask, $mainLanguageId, $languageSettings)
199
    {
@@ 261-308 (lines=48) @@
258
    /**
259
     * @see \eZ\Publish\SPI\Search\Handler::findLocations
260
     */
261
    public function findLocations(LocationQuery $query, array $languageFilter = array())
262
    {
263
        if (!isset($languageFilter['languages'])) {
264
            $languageFilter['languages'] = array();
265
        }
266
267
        if (!isset($languageFilter['useAlwaysAvailable'])) {
268
            $languageFilter['useAlwaysAvailable'] = true;
269
        }
270
271
        $start = microtime(true);
272
        $query->filter = $query->filter ?: new Criterion\MatchAll();
273
        $query->query = $query->query ?: new Criterion\MatchAll();
274
275
        if (count($query->facetBuilders)) {
276
            throw new NotImplementedException('Facets are not supported by the legacy search engine.');
277
        }
278
279
        // The legacy search does not know about scores, so we just
280
        // combine the query with the filter
281
        $data = $this->locationGateway->find(
282
            new Criterion\LogicalAnd(array($query->query, $query->filter)),
283
            $query->offset,
284
            $query->limit,
285
            $query->sortClauses,
286
            $languageFilter,
287
            $query->performCount
288
        );
289
290
        $result = new SearchResult();
291
        $result->time = microtime(true) - $start;
292
        $result->totalCount = $data['count'];
293
        $locationList = $this->locationMapper->createLocationsFromRows($data['rows']);
294
295
        foreach ($locationList as $index => $location) {
296
            $searchHit = new SearchHit();
297
            $searchHit->valueObject = $location;
298
            $searchHit->matchedTranslation = $this->extractMatchedLanguage(
299
                $data['rows'][$index]['language_mask'],
300
                $data['rows'][$index]['initial_language_id'],
301
                $languageFilter
302
            );
303
304
            $result->searchHits[] = $searchHit;
305
        }
306
307
        return $result;
308
    }
309
310
    /**
311
     * Suggests a list of values for the given prefix.