<commit_before><?php

trait Search {

	protected function getSearchResults($request, $amount = 20) {
		
			$results = $this->search($request ?: "", "track", "song-database");
			//dd($results);

			$start = (Paginator::getCurrentPage() - 1) * $amount;

			$count = $results["hits"]["total"];

			$slice = array_slice($results["hits"]["hits"], $start, $amount);

			$paginator = Paginator::make($slice, $count, $amount);

			View::share("time", $results["took"]);

			return $paginator;

	}

	public function search($terms, $type, $index) {

		$params = [
			"type" => $type,
			"index" => $index,
			"ignore" => [
				400,
				404
			],
			"body" => [
				"query" => [
					"query_string" => [
						"fields" => ["title", "artist", "album", "tags", "_id"],
						"default_operator" => "and",
						"query" => $terms,
					]
				],
			],
		];

		return $this->client->search($params);

	}

	public function index($track) {
		$tmp = [];

		$tmp["type"] = "track";
		$tmp["index"] = "song-database";
		$tmp["id"] = $track["id"];

		$tmp["body"] = [
			"album" => $track["album"],
			"tags" => $track["tags"],
			"title" => $track["track"],
			"artist" => $track["artist"],
			"id" => $track["id"],
			"acceptor" => $track["accepter"],
			"editor" => $track["lasteditor"],
			"requests" => $track["requestcount"],
			"lastplayed" => $track["lastplayed"],<commit_msg>Fix search pagination.<commit_after><?php

trait Search {

	protected function getSearchResults($request, $amount = 20) {
		
			$results = $this->search($request ?: "", "track", "song-database");
			//dd($results);

			$start = (Paginator::getCurrentPage() - 1) * $amount;

			$count = $results["hits"]["total"];

			$slice = array_slice($results["hits"]["hits"], $start, $amount);

			$paginator = Paginator::make($slice, $count, $amount);

			View::share("time", $results["took"]);

			return $paginator;

	}

	public function search($terms, $type, $index) {

		$params = [
			"type" => $type,
			"index" => $index,
			"ignore" => [
				400,
				404
			],
			"body" => [
				"size" => 10000,
				"query" => [
					"query_string" => [
						"fields" => ["title", "artist", "album", "tags", "_id"],
						"default_operator" => "and",
						"query" => $terms,
					]
				],
			],
		];

		return $this->client->search($params);

	}

	public function index($track) {
		$tmp = [];

		$tmp["type"] = "track";
		$tmp["index"] = "song-database";
		$tmp["id"] = $track["id"];

		$tmp["body"] = [
			"album" => $track["album"],
			"tags" => $track["tags"],
			"title" => $track["track"],
			"artist" => $track["artist"],
			"id" => $track["id"],
			"acceptor" => $track["accepter"],
			"editor" => $track["lasteditor"],
			"requests" => $track["requestcount"],
			"lastplayed" => $track["lastplayed"],
{'fraction_non_alphanumeric': 0.2512708787218591, 'fraction_numerical': 0.008351488743645606, 'mean_word_length': 3.5090016366612113, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 46, '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': '3474428', 'n_tokens_mistral': 1212, 'n_tokens_neox': 977, 'n_words': 179}