<commit_before>package edu.sdsu.its.rohan_search;

import com.google.gson.Gson;
import edu.sdsu.its.rohan_search.models.File;
import edu.sdsu.its.rohan_search.models.HTML_Table;
import org.apache.log4j.Logger;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

@Path("/")
public class Web {
    @GET
    @Path("echo")
    @Produces(MediaType.TEXT_PLAIN)
    public String echo(@QueryParam("m") final String message) {
        Logger.getLogger(getClass()).info("Request received with m=" + message);
        return "echo: " + message;
    }

    @GET
    @Path("search")
    @Produces(MediaType.TEXT_HTML)
    public Response search(@QueryParam("q") final String query, @QueryParam("t") final String title) {
        Logger.getLogger(getClass()).info(String.format("Recieved Request to search for q:%s & t:%s", query, title));

        List<File> results;
        if (title != null) {
            results = DB.getInstance().search_phrase(title);
        } else if (query != null) {
            results = DB.getInstance().search(query);
        } else {
            results = new ArrayList<>();
        }

        if (query != null) {
            Logger.getLogger(getClass()).info(String.format("Search for %s returned %d results", query, results.size()));
        } else {
            Logger.getLogger(getClass()).info(String.format("Search for %s returned %d results", title, results.size()));
        }

        String content;
        Response.ResponseBuilder status;
        if (results.size() != 0) {
            HTML_Table table = new HTML_Table();
            results.forEach(table::addFile);
            content = table.getHtml_content();
            status = Response.status(Response.Status.OK);
        } else {
            content = "No Files Found!";
            status = Response.status(Response.Status.OK);
        }

        return status.entity(content).build();<commit_msg>Improved Search Algorithm<commit_after>package edu.sdsu.its.rohan_search;

import com.google.gson.Gson;
import edu.sdsu.its.rohan_search.models.File;
import edu.sdsu.its.rohan_search.models.HTML_Table;
import org.apache.log4j.Logger;

import javax.ws.rs.*;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.ArrayList;
import java.util.List;

@Path("/")
public class Web {
    @GET
    @Path("echo")
    @Produces(MediaType.TEXT_PLAIN)
    public String echo(@QueryParam("m") final String message) {
        Logger.getLogger(getClass()).info("Request received with m=" + message);
        return "echo: " + message;
    }

    @GET
    @Path("search")
    @Produces(MediaType.TEXT_HTML)
    public Response search(@QueryParam("q") final String query, @QueryParam("t") final String title) {
        Logger.getLogger(getClass()).info(String.format("Recieved Request to search for q:%s & t:%s", query, title));

        List<File> results;
        if (title != null) {
            results = DB.getInstance().search_phrase(title.trim());
        } else if (query != null) {
            results = DB.getInstance().search(query.trim());
        } else {
            results = new ArrayList<>();
        }

        if (query != null) {
            Logger.getLogger(getClass()).info(String.format("Search for %s returned %d results", query, results.size()));
        } else {
            Logger.getLogger(getClass()).info(String.format("Search for %s returned %d results", title, results.size()));
        }

        String content;
        Response.ResponseBuilder status;
        if (results.size() != 0) {
            HTML_Table table = new HTML_Table();
            results.forEach(table::addFile);
            content = table.getHtml_content();
            status = Response.status(Response.Status.OK);
        } else {
            content = "No Files Found!";
            status = Response.status(Response.Status.OK);
        }

        return status.entity(content).build();
{'fraction_non_alphanumeric': 0.1402321083172147, 'fraction_numerical': 0.0009671179883945841, 'mean_word_length': 2.784995425434584, 'pattern_counts': {'":': 0, '<': 7, '<?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': '1881271', 'n_tokens_mistral': 1196, 'n_tokens_neox': 1201, 'n_words': 259}