<commit_before>class BookmarksController < ApplicationController
	def index
		authorize Bookmark

		@page = params[:page] ? params[:page] : 1
		unless params[:user].present?
			redirect_to user_bookmarks_path(user: current_user, page: @page)
			return
		end

		@per_page = Kaminari.config.default_per_page
		@bookmarks = Bookmark.owned_by(User.friendly.find(params[:user])).page @page
	end

	def new
		authorize Bookmark
		@bookmark = Bookmark.new
		@tags = []
	end

	def create
		authorize Bookmark
		bookmark = Bookmark.create(bookmark_params.merge({user: current_user}))
		unless bookmark.blank?
			new_tags = params[:bookmark][:tags].split(',').collect do |item|
				Tag.find_or_create_by(name: item)
			end
			bookmark.tags << new_tags
			bookmark.save
		end

		redirect_to bookmark, notice: 'Bookmark was successfully created.'
	end

	def show
		@bookmark = Bookmark.find(params[:id])
		authorize @bookmark
		@tags = @bookmark.tags
	end

	def edit
		@bookmark = Bookmark.find(params[:id])
		authorize @bookmark
		@tags = @bookmark.tags
	end

	def update
		bookmark = Bookmark.find(params[:id])
		authorize bookmark
		Bookmark.update(bookmark, bookmark_params.merge({user: current_user}))
		redirect_to bookmark_path(bookmark)
	end

	def search
		# lock it down for now
		authorize Bookmark
		# should move this functionality to run directly from the web server ahead of Rails (metal)
		@bookmarks = Bookmark.where("title LIKE ? OR url LIKE ?", "%#{params[:q]}%", "%#{params[:q]}%").limit(20)
		respond_to do |format|
			format.html {render :text => "search: #{params[:q]} => #{@bookmarks.collect_concat {|b| [b.title, b.url]}}", status: :ok}
			format.js {render :json => @bookmarks, status: :ok}
		end
	end

	private
		def bookmark_params
			params.require(:bookmark).permit(:url, :title, :private, :tags)
		end
end<commit_msg>trying out returning JSON from search controller<commit_after>class BookmarksController < ApplicationController
	def index
		authorize Bookmark

		@page = params[:page] ? params[:page] : 1
		unless params[:user].present?
			redirect_to user_bookmarks_path(user: current_user, page: @page)
			return
		end

		@per_page = Kaminari.config.default_per_page
		@bookmarks = Bookmark.owned_by(User.friendly.find(params[:user])).page @page
	end

	def new
		authorize Bookmark
		@bookmark = Bookmark.new
		@tags = []
	end

	def create
		authorize Bookmark
		bookmark = Bookmark.create(bookmark_params.merge({user: current_user}))
		unless bookmark.blank?
			new_tags = params[:bookmark][:tags].split(',').collect do |item|
				Tag.find_or_create_by(name: item)
			end
			bookmark.tags << new_tags
			bookmark.save
		end

		redirect_to bookmark, notice: 'Bookmark was successfully created.'
	end

	def show
		@bookmark = Bookmark.find(params[:id])
		authorize @bookmark
		@tags = @bookmark.tags
	end

	def edit
		@bookmark = Bookmark.find(params[:id])
		authorize @bookmark
		@tags = @bookmark.tags
	end

	def update
		bookmark = Bookmark.find(params[:id])
		authorize bookmark
		Bookmark.update(bookmark, bookmark_params.merge({user: current_user}))
		redirect_to bookmark_path(bookmark)
	end

	def search
		# lock it down for now
		authorize Bookmark
		# should move this functionality to run directly from the web server ahead of Rails (metal)
		@bookmarks = Bookmark.where("title LIKE ? OR url LIKE ?", "%#{params[:q]}%", "%#{params[:q]}%").limit(10)
		respond_to do |format|
			# format.html {render :text => "search: #{params[:q]} => #{@bookmarks.collect_concat {|b| [b.title, b.url]}}", status: :ok}
			format.html {render :json => @bookmarks, status: :ok}
			format.js {render :json => @bookmarks, status: :ok}
		end
	end

	private
		def bookmark_params
			params.require(:bookmark).permit(:url, :title, :private, :tags)
		end
end
{'fraction_non_alphanumeric': 0.12732589048378523, 'fraction_numerical': 0.001594896331738437, 'mean_word_length': 4.509516837481699, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2219315', 'n_tokens_mistral': 1402, 'n_tokens_neox': 1261, 'n_words': 321}