<commit_before>package org.intermine.web.struts;

/*
 * Copyright (C) 2002-2008 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.HashMap;
import java.util.Map;

import org.intermine.objectstore.query.ConstraintOp;
import org.intermine.pathquery.PathNode;

import org.intermine.web.logic.Constants;
import org.intermine.web.logic.profile.Profile;
import org.intermine.web.logic.query.QueryMonitorTimeout;
import org.intermine.web.logic.session.SessionMethods;
import org.intermine.web.logic.template.TemplateHelper;
import org.intermine.web.logic.template.TemplateQuery;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;

/**
 * @author <NAME>
 *
 */
public class QuickSearchAction extends InterMineAction
{

    /**
     * Method called when user has submitted search form.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @return an ActionForward object defining where control goes next
     * @exception Exception if the application business logic throws
     *  an exception
     */
    @Override
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 @SuppressWarnings("unused") HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext context = session.getServletContext();
        QuickSearchForm qsf = (QuickSearchForm) form;
        String qsType = qsf.getQuickSearchType();
        session.setAttribute("quickSearchType", qsType);
        Profile profile = ((Profile) session.getAttribute(Constants.PROFILE));
        if (qsType.equals("ids")) {
            Map webPropertiesMap = (Map) context.getAttribute(Constants.WEB_PROPERTIES);

            String templateName = (String) webPropertiesMap.get("begin.browse.template");
            String templateType = "global";

            SessionMethods.logTemplateQueryUse(session, templateType, templateName);
            String userName = profile.getUsername();
            TemplateQuery template = TemplateHelper.findTemplate(context, session, userName,
                                                                 templateName, templateType);
            QueryMonitorTimeout clientState = new QueryMonitorTimeout(Constants.
                                                                      QUERY_TIMEOUT_SECONDS * 1000);
            MessageResources messages =
                (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

            Map<String, Object> valuesMap = new HashMap <String, Object> ();
            Map <String, ConstraintOp> constraintOpsMap = new HashMap <String, ConstraintOp> ();

            PathNode node = (template.getEditableNodes().get(0));

            valuesMap.put(node.getPathString(), qsf.getParsedValue());
            constraintOpsMap.put(node.getPathString(), ConstraintOp.EQUALS);

            TemplateQuery queryCopy = TemplateHelper.editTemplate(valuesMap,
                    constraintOpsMap, template, null, new HashMap<String, String>());
            String qid = SessionMethods.startQuery(clientState, session, messages,
                                                   false, queryCopy);
            Thread.sleep(200);
            return new ForwardParameters(mapping.findForward("waiting"))
                .addParameter("qid", qid)<commit_msg>after quicksearch, remove the last query ran.  otherwise the original template query shows up on the results page.  there's probably a more graceful way to handle this, but I couldn't think of one.  I don't see a way to determine if a user has just run the quick search - other than to add a new special flag.<commit_after>package org.intermine.web.struts;

/*
 * Copyright (C) 2002-2008 FlyMine
 *
 * This code may be freely distributed and modified under the
 * terms of the GNU Lesser General Public Licence.  This should
 * be distributed with the code.  See the LICENSE file for more
 * information or http://www.gnu.org/copyleft/lesser.html.
 *
 */

import java.util.HashMap;
import java.util.Map;

import org.intermine.objectstore.query.ConstraintOp;
import org.intermine.pathquery.PathNode;

import org.intermine.web.logic.Constants;
import org.intermine.web.logic.profile.Profile;
import org.intermine.web.logic.query.QueryMonitorTimeout;
import org.intermine.web.logic.session.SessionMethods;
import org.intermine.web.logic.template.TemplateHelper;
import org.intermine.web.logic.template.TemplateQuery;

import javax.servlet.ServletContext;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import org.apache.struts.Globals;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.util.MessageResources;

/**
 * @author <NAME>
 *
 */
public class QuickSearchAction extends InterMineAction
{

    /**
     * Method called when user has submitted search form.
     *
     * @param mapping The ActionMapping used to select this instance
     * @param form The optional ActionForm bean for this request (if any)
     * @param request The HTTP request we are processing
     * @param response The HTTP response we are creating
     * @return an ActionForward object defining where control goes next
     * @exception Exception if the application business logic throws
     *  an exception
     */
    @Override
    public ActionForward execute(ActionMapping mapping,
                                 ActionForm form,
                                 HttpServletRequest request,
                                 @SuppressWarnings("unused") HttpServletResponse response)
        throws Exception {
        HttpSession session = request.getSession();
        ServletContext context = session.getServletContext();
        QuickSearchForm qsf = (QuickSearchForm) form;
        String qsType = qsf.getQuickSearchType();
        session.setAttribute("quickSearchType", qsType);
        Profile profile = ((Profile) session.getAttribute(Constants.PROFILE));
        if (qsType.equals("ids")) {
            Map webPropertiesMap = (Map) context.getAttribute(Constants.WEB_PROPERTIES);

            // remove the last query ran, otherwise the old query will show up on the results page
            session.removeAttribute(Constants.QUERY);

            String templateName = (String) webPropertiesMap.get("begin.browse.template");
            String templateType = "global";

            SessionMethods.logTemplateQueryUse(session, templateType, templateName);

            String userName = profile.getUsername();
            TemplateQuery template = TemplateHelper.findTemplate(context, session, userName,
                                                                 templateName, templateType);
            QueryMonitorTimeout clientState = new QueryMonitorTimeout(Constants.
                                                                      QUERY_TIMEOUT_SECONDS * 1000);
            MessageResources messages =
                (MessageResources) request.getAttribute(Globals.MESSAGES_KEY);

            Map<String, Object> valuesMap = new HashMap <String, Object> ();
            Map <String, ConstraintOp> constraintOpsMap = new HashMap <String, ConstraintOp> ();

            PathNode node = (template.getEditableNodes().get(0));

            valuesMap.put(node.getPathString(), qsf.getParsedValue());
            constraintOpsMap.put(node.getPathString(), ConstraintOp.EQUALS);

            TemplateQuery queryCopy = TemplateHelper.editTemplate(valuesMap,
                    constraintOpsMap, template, null, new HashMap<String, String>());
            String qid = SessionMethods.startQuery(clientState, session, messages, false,
                                                   queryCopy);
            Thread.sleep(200);
            return new ForwardParameters(mapping.findForward("waiting"))
                .addParameter("qid", qid)
{'fraction_non_alphanumeric': 0.08311629487034311, 'fraction_numerical': 0.003623598686445476, 'mean_word_length': 2.739204064352244, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 15, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 20, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3141514', 'n_tokens_mistral': 2166, 'n_tokens_neox': 2112, 'n_words': 594}