You can prepare all the common logic you need but only apply pagination for the HTML format:
def index
@search = Group.search(params[:q])
@groups = @search.result
respond_to do |format|
format.html { @groups = @groups.page(params[:page]) }
format.json { render :json => @groups }
end
end