<commit_before><?php

/* Search with multiple optional parameters */

Route::get('/search/creature', function() {

  if ( !isset($_GET['id']) && !isset($_GET['name']) && !isset($_GET['subname']) )
    return;

  $query = DB::table('creature_template');

  if (isset($_GET['id']))
    $query->where('entry', '=', $_GET['id']);

  if (isset($_GET['name']))
    $query->where('name', 'LIKE', "%". $_GET['name'] ."%");

  if (isset($_GET['subname']))
    $query->where('subname', 'LIKE', "%". $_GET['subname'] ."%");

  $results = $query->orderBy('entry')->get();

  return Response::json($results);
});


/* Creatures */

Route::get('/creature/template/{id}', function($id) {
  $results = DB::connection('world')->select("SELECT * FROM creature_template WHERE entry = ?", [$id]);

  return Response::json($results);
})
  ->where('id', '[0-9]+');

Route::get('/creature/template/name/{id}', function($id) {<commit_msg>Improved creature search with multiple optional params<commit_after><?php

/* Search with multiple optional parameters */

Route::get('/search/creature', function() {

  if ( !isset($_GET['id']) && !isset($_GET['name']) && !isset($_GET['subname']) )
    return;

  $query = DB::table('creature_template');

  if (isset($_GET['id']) && $_GET['id'] != "")
    $query->where('entry', 'LIKE', "%". $_GET['id'] ."%");

  if (isset($_GET['name']) && $_GET['name'] != "")
    $query->where('name', 'LIKE', "%". $_GET['name'] ."%");

  if (isset($_GET['subname']) && $_GET['subname'] != "")
    $query->where('subname', 'LIKE', "%". $_GET['subname'] ."%");

  $results = $query->orderBy('entry')->get();

  return Response::json($results);
});


/* Creatures */

Route::get('/creature/template/{id}', function($id) {
  $results = DB::connection('world')->select("SELECT * FROM creature_template WHERE entry = ?", [$id]);

  return Response::json($results);
})
  ->where('id', '[0-9]+');

Route::get('/creature/template/name/{id}', function($id) {
{'fraction_non_alphanumeric': 0.2838114754098361, 'fraction_numerical': 0.0020491803278688526, 'mean_word_length': 5.160883280757098, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 17, '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': '7616376', 'n_tokens_mistral': 652, 'n_tokens_neox': 636, 'n_words': 108}