<commit_before>package main

import (
	"encoding/json"
	"fmt"
	log "github.com/cihub/seelog"
	"github.com/crufter/borg/types"
	httpr "github.com/julienschmidt/httprouter"
	"github.com/olivere/elastic"
	"io/ioutil"
	"net/http"
	"reflect"
)

var (
	client *elastic.Client
)

func init() {
	cl, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL("http://127.0.0.1:9200"))
	if err != nil {
		panic(err)
	}
	client = cl
}

func main() {
	r := httpr.New()
	r.GET("/v1/query", query)
	//r.PUT("/v1/problem/:id", update)
	//r.POST("/v1/problem", save)
	//r.POST()
	log.Info("Starting http server")
	log.Critical(http.ListenAndServe(fmt.Sprintf(":%v", 9992), r))
}

func query(w http.ResponseWriter, r *http.Request, p httpr.Params) {
	res, err := client.Search().Index("borg").Type("problem").From(0).Size(5).Query(
		elastic.NewQueryStringQuery(r.FormValue("q"))).Do()
	if err != nil {
		panic(err)
	}
	all := []types.Problem{}
	var ttyp types.Problem
	for _, item := range res.Each(reflect.TypeOf(ttyp)) {
		if t, ok := item.(types.Problem); ok {
			all = append(all, t)
		}
	}
	bs, err := json.Marshal(all)
	if err != nil {
		panic(err)
	}
	fmt.Fprint(w, string(bs))
}

func save(w http.ResponseWriter, r *http.Request, p httpr.Params) {
	body, err := ioutil.ReadAll(r.Body)
	if err != nil {
		panic(err)
	}
	b64encoded := []string{}
	err = json.Unmarshal(body, &b64encoded)
	if err != nil {
		panic(err)
	}
	ss := []types.Solution{}
	log.Debugf("Putting services %v", ss)
}<commit_msg>Parse limit on query on backend<commit_after>package main

import (
	"encoding/json"
	"fmt"
	log "github.com/cihub/seelog"
	"github.com/crufter/borg/types"
	httpr "github.com/julienschmidt/httprouter"
	"github.com/olivere/elastic"
	"net/http"
	"reflect"
	"strconv"
)

var (
	client *elastic.Client
)

func init() {
	cl, err := elastic.NewClient(elastic.SetSniff(false), elastic.SetURL("http://127.0.0.1:9200"))
	if err != nil {
		panic(err)
	}
	client = cl
}

func main() {
	r := httpr.New()
	r.GET("/v1/query", query)
	log.Info("Starting http server")
	log.Critical(http.ListenAndServe(fmt.Sprintf(":%v", 9992), r))
}

func query(w http.ResponseWriter, r *http.Request, p httpr.Params) {
	size := 5
	s, err := strconv.ParseInt(r.FormValue("l"), 10, 32)
	if err == nil && s > 0 {
		size = int(s)
	}
	if s > 50 {
		s = 50
	}
	res, err := client.Search().Index("borg").Type("problem").From(0).Size(size).Query(
		elastic.NewQueryStringQuery(r.FormValue("q"))).Do()
	if err != nil {
		panic(err)
	}
	all := []types.Problem{}
	var ttyp types.Problem
	for _, item := range res.Each(reflect.TypeOf(ttyp)) {
		if t, ok := item.(types.Problem); ok {
			all = append(all, t)
		}
	}
	bs, err := json.Marshal(all)
	if err != nil {
		panic(err)
	}
	fmt.Fprint(w, string(bs))
}
{'fraction_non_alphanumeric': 0.19644798840159478, 'fraction_numerical': 0.017760057992026096, 'mean_word_length': 3.8849557522123894, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 5, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, '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': '5849982', 'n_tokens_mistral': 1206, 'n_tokens_neox': 1131, 'n_words': 222}