Code Duplication    Length = 44-50 lines in 2 locations

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

@@ 143-192 (lines=50) @@
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
        // The legacy search does not know about scores, so that we just
158
        // combine the query with the filter
159
        $filter = new Criterion\LogicalAnd(array($query->query, $query->filter));
160
161
        $data = $this->gateway->find(
162
            $filter,
163
            $query->offset,
164
            $query->limit,
165
            $query->sortClauses,
166
            $languageFilter,
167
            $query->performCount
168
        );
169
170
        $result = new SearchResult();
171
        $result->time = microtime(true) - $start;
172
        $result->totalCount = $data['count'];
173
        $contentInfoList = $this->contentMapper->extractContentInfoFromRows(
174
            $data['rows'],
175
            '',
176
            'main_tree_'
177
        );
178
179
        foreach ($contentInfoList as $index => $contentInfo) {
180
            $searchHit = new SearchHit();
181
            $searchHit->valueObject = $contentInfo;
182
            $searchHit->matchedTranslation = $this->extractMatchedLanguage(
183
                $data['rows'][$index]['language_mask'],
184
                $data['rows'][$index]['initial_language_id'],
185
                $languageFilter
186
            );
187
188
            $result->searchHits[] = $searchHit;
189
        }
190
191
        return $result;
192
    }
193
194
    protected function extractMatchedLanguage($languageMask, $mainLanguageId, $languageSettings)
195
    {
@@ 257-300 (lines=44) @@
254
    /**
255
     * @see \eZ\Publish\SPI\Search\Handler::findLocations
256
     */
257
    public function findLocations(LocationQuery $query, array $languageFilter = array())
258
    {
259
        if (!isset($languageFilter['languages'])) {
260
            $languageFilter['languages'] = array();
261
        }
262
263
        if (!isset($languageFilter['useAlwaysAvailable'])) {
264
            $languageFilter['useAlwaysAvailable'] = true;
265
        }
266
267
        $start = microtime(true);
268
        $query->filter = $query->filter ?: new Criterion\MatchAll();
269
        $query->query = $query->query ?: new Criterion\MatchAll();
270
271
        // The legacy search does not know about scores, so we just
272
        // combine the query with the filter
273
        $data = $this->locationGateway->find(
274
            new Criterion\LogicalAnd(array($query->query, $query->filter)),
275
            $query->offset,
276
            $query->limit,
277
            $query->sortClauses,
278
            $languageFilter,
279
            $query->performCount
280
        );
281
282
        $result = new SearchResult();
283
        $result->time = microtime(true) - $start;
284
        $result->totalCount = $data['count'];
285
        $locationList = $this->locationMapper->createLocationsFromRows($data['rows']);
286
287
        foreach ($locationList as $index => $location) {
288
            $searchHit = new SearchHit();
289
            $searchHit->valueObject = $location;
290
            $searchHit->matchedTranslation = $this->extractMatchedLanguage(
291
                $data['rows'][$index]['language_mask'],
292
                $data['rows'][$index]['initial_language_id'],
293
                $languageFilter
294
            );
295
296
            $result->searchHits[] = $searchHit;
297
        }
298
299
        return $result;
300
    }
301
302
    /**
303
     * Suggests a list of values for the given prefix.