Code Duplication    Length = 48-54 lines in 2 locations

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

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