<commit_before>import lunr from "lunr";

export const handler = (event, context, callback) => {
  (async () => {
    const json = fs.readFileSync(require.resolve("./index.json"));

    var index = lunr(function() {
      this.ref("url");
      this.field("title", { boost: 10 });
      this.field("category");
      this.field("excerpt");

      json.forEach(function(doc) {
        this.add(doc);
      }, this);
    });

    const results = index.search(query);

    callback(null, {
      statusCode: 200,
      body: JSON.stringify(results)
    });<commit_msg>Fix query handling in search<commit_after>import lunr from "lunr";

export const handler = (event, context, callback) => {
  (async () => {
    const query = event.queryStringParameters.q;

    if (!query || query === "") {
      callback(null, {
        statusCode: 400
      });
    } else {
      const json = fs.readFileSync(require.resolve("./index.json"));

      var index = lunr(function() {
        this.ref("url");
        this.field("title", { boost: 10 });
        this.field("category");
        this.field("excerpt");

        json.forEach(function(doc) {
          this.add(doc);
        }, this);
      });

      const results = index.search(query);

      callback(null, {
        statusCode: 200,
        body: JSON.stringify(results)
      });
    }
{'fraction_non_alphanumeric': 0.16729182295573894, 'fraction_numerical': 0.009752438109527382, 'mean_word_length': 2.3857868020304567, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '3714524', 'n_tokens_mistral': 422, 'n_tokens_neox': 397, 'n_words': 82}