/*
 * See the NOTICE file distributed with this work for additional
 * information regarding copyright ownership.
 *
 * This is free software; you can redistribute it and/or modify it
 * under the terms of the GNU Lesser General Public License as
 * published by the Free Software Foundation; either version 2.1 of
 * the License, or (at your option) any later version.
 *
 * This software is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
 * Lesser General Public License for more details.
 *
 * You should have received a copy of the GNU Lesser General Public
 * License along with this software; if not, write to the Free
 * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
 * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
 */

package org.xwiki.extension.repository.xwiki.internal.resources;

import javax.ws.rs.DefaultValue;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.QueryParam;

import org.xwiki.component.annotation.Component;
import org.xwiki.extension.repository.xwiki.Resources;
import org.xwiki.extension.repository.xwiki.model.jaxb.ExtensionsSearchResult;
import org.xwiki.query.Query;
import org.xwiki.query.QueryException;

/**
 * @version $Id$
 * @since 3.2M3
 */
@Component("org.xwiki.extension.repository.xwiki.internal.resources.SearchRESTResource")
@Path(Resources.SEARCH)
public class SearchRESTResource extends AbstractExtensionRESTResource
{
    /**
     * @since 3.3M2
     */
    @GET
    public ExtensionsSearchResult search(@QueryParam(Resources.QPARAM_SEARCH_QUERY) @DefaultValue("") String pattern,
        @QueryParam(Resources.QPARAM_LIST_START) @DefaultValue("0") int offset,
        @QueryParam(Resources.QPARAM_LIST_NUMBER) @DefaultValue("-1") int number,
        @QueryParam(Resources.QPARAM_SEARCH_REQUIRETOTALHITS) @DefaultValue("true") boolean requireTotalHits)
        throws QueryException
    {
        String where =
            "extension.id like :pattern or extension.name like :pattern or extension.description like :pattern";

        ExtensionsSearchResult result = this.objectFactory.createExtensionsSearchResult();

        result.setOffset(offset);

        if (requireTotalHits) {
            Query query = createExtensionsCountQuery(null, where);

            query.bindValue("pattern", '%' + pattern + '%');

            result.setTotalHits((int) getExtensionsCountResult(query));
        } else {
            result.setTotalHits(-1);
        }

        if (number != 0 && (result.getTotalHits() == -1 || offset < result.getTotalHits())) {
            Query query = createExtensionsQuery(null, where, offset, number);

            query.bindValue("pattern", '%' + pattern + '%');

            getExtensions(result.getExtensions(), query);
        }

        return result;
    }
}

@@ -1551,16 +1551,206 @@
 e%0A%7B%0A
+    private static final String WHERE = %22extension.id like :pattern or extension.name like :pattern%22%0A        + %22 or extension.summary like :pattern or extension.description like :pattern%22;%0A%0A
     /**%0A
     
@@ -1745,16 +1745,16 @@
     /**%0A
-
      * @
@@ -2212,145 +2212,8 @@
   %7B%0A
-        String where =%0A            %22extension.id like :pattern or extension.name like :pattern or extension.description like :pattern%22;%0A%0A
     
@@ -2426,21 +2426,21 @@
 y(null, 
-where
+WHERE
 );%0A%0A    
@@ -2786,13 +2786,13 @@
 ll, 
-where
+WHERE
 , of

Add summary in the simple search on XR