Code Duplication    Length = 48-54 lines in 2 locations

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

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