<commit_before>#!/usr/bin/python
# -*- coding: utf-8 -*-

from ujson import dumps
from tornado import gen

from holmes.models import Page
from holmes.handlers import BaseHandler


class SearchHandler(BaseHandler):

    @gen.coroutine
    def get(self):
        term = self.get_argument('term')

        pages = yield Page.objects.filter(url=term, last_review_date__is_null=False).find_all()

        if not pages:
            self.set_status(404)
            self.finish()
            return

        pages_json = []

        for page in pages:
            yield page.load_references(['last_review'])

            pages_json.append({
                "uuid": str(page.uuid),
                "title": page.title,
                "url": page.url,
                "reviewId": str(page.last_review.uuid)
            })

        self.write(dumps(pages_json))
        self.finish()<commit_msg>Changed write in search handler to use write_json<commit_after>#!/usr/bin/python
# -*- coding: utf-8 -*-

from tornado import gen

from holmes.models import Page
from holmes.handlers import BaseHandler


class SearchHandler(BaseHandler):

    @gen.coroutine
    def get(self):
        term = self.get_argument('term')

        pages = yield Page.objects.filter(url=term, last_review_date__is_null=False).find_all()

        pages_json = []

        for page in pages:
            yield page.load_references(['last_review'])

            pages_json.append({
                "uuid": str(page.uuid),
                "title": page.title,
                "url": page.url,
                "reviewId": str(page.last_review.uuid)
            })

        self.write_json(pages_json)
        self.finish()
{'fraction_non_alphanumeric': 0.1124330755502677, 'fraction_numerical': 0.00297441998810232, 'mean_word_length': 2.0749542961608776, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, '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': '6507078', 'n_tokens_mistral': 506, 'n_tokens_neox': 478, 'n_words': 104}