<commit_before>from django.http import HttpResponse
from django.shortcuts import render

from .utils import check_input
from .utils import get_or_create_experiment

from ifind.search import Query
from ifind.search import EngineFactory


def search(request):
    """
    Accepts GET request containing query terms,
    searches and returns results as JSON.

    """
    # invalid HTTP method
    if request.method != 'GET':
        return HttpResponse(status=405)

    # checks input for validity
    query_terms = check_input(request.GET.get('q', ''))

    # bad request
    if not query_terms:
        return HttpResponse(status=400)

    # get exp ID and load experiment
    exp_id = request.session.get('exp_id', False)
    experiment = get_or_create_experiment(exp_id)

    # execute query
    engine = EngineFactory('wikipedia')
    query = Query(query_terms, top=experiment['top'])
    response = engine.search(query)

    return HttpResponse(response.to_json(), content_type='application/json')<commit_msg>search view tests bing and image search for now<commit_after>from django.http import HttpResponse
from django.shortcuts import render

from .utils import check_input
from .utils import get_or_create_experiment

from ifind.search import Query
from ifind.search import EngineFactory


def search(request):
    """
    Accepts GET request containing query terms,
    searches and returns results as JSON.

    """
    # invalid HTTP method
    if request.method != 'GET':
        return HttpResponse(status=405)

    # checks input for validity
    query_terms = check_input(request.GET.get('q', ''))

    # bad request
    if not query_terms:
        return HttpResponse(status=400)

    # get exp ID and load experiment
    exp_id = request.session.get('exp_id', False)
    experiment = get_or_create_experiment(exp_id)

    # execute query
    engine = EngineFactory('bing', api_key="")
    query = Query(query_terms, top=experiment['top'], result_type="image")
    response = engine.search(query)

    return HttpResponse(response.to_json(), content_type='application/json')
{'fraction_non_alphanumeric': 0.08908045977011494, 'fraction_numerical': 0.005747126436781609, 'mean_word_length': 3.8694638694638694, 'pattern_counts': {'":': 0, '<': 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': '1214047', 'n_tokens_mistral': 607, 'n_tokens_neox': 578, 'n_words': 173}