<commit_before>package cn.edu.zjnu.acm.judge.user;

import cn.edu.zjnu.acm.judge.domain.User;
import cn.edu.zjnu.acm.judge.exception.MessageException;
import cn.edu.zjnu.acm.judge.mapper.UserMapper;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SearchUserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/searchuser", method = {RequestMethod.GET, RequestMethod.HEAD})
    protected String searchuser(HttpServletRequest request,
            @RequestParam(value = "user_id", defaultValue = "") String keyword,
            @RequestParam(value = "position", required = false) String position) {
        if (keyword.length() < 2) {
            throw new MessageException("search key word whose length must be greater than 2");
        }
        String like = keyword;
        if (position == null) {
            like = "%" + like + "%";
        } else if (position.equalsIgnoreCase("begin")) {
            like += "%";
        } else {
            like = "%" + like;
        }
        List<User> users = userMapper.findAllBySearch(like);
        if (users.isEmpty()) {
            throw new MessageException("Sorry, no user founded");
        }

        request.setAttribute("query", keyword);
        request.setAttribute("users", users);
        return "users/search";

    }

}<commit_msg>polish<commit_after>package cn.edu.zjnu.acm.judge.user;

import cn.edu.zjnu.acm.judge.domain.User;
import cn.edu.zjnu.acm.judge.exception.MessageException;
import cn.edu.zjnu.acm.judge.mapper.UserMapper;
import java.util.List;
import javax.servlet.http.HttpServletRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;

@Controller
public class SearchUserController {

    @Autowired
    private UserMapper userMapper;

    @RequestMapping(value = "/searchuser", method = {RequestMethod.GET, RequestMethod.HEAD})
    protected String searchuser(HttpServletRequest request,
            @RequestParam(value = "user_id", defaultValue = "") String keyword,
            @RequestParam(value = "position", required = false) String position) {
        if (keyword.length() < 2) {
            throw new MessageException("search key word whose length must be greater than 2");
        }
        String like = keyword;
        if (position == null) {
            like = "%" + like + "%";
        } else if (position.equalsIgnoreCase("begin")) {
            like += "%";
        } else {
            like = "%" + like;
        }
        List<User> users = userMapper.findAllBySearch(like);
        if (users.isEmpty()) {
            throw new MessageException("Sorry, no user found");
        }

        request.setAttribute("query", keyword);
        request.setAttribute("users", users);
        return "users/search";

    }

}
{'fraction_non_alphanumeric': 0.11936735302894658, 'fraction_numerical': 0.001193673530289466, 'mean_word_length': 3.112883435582822, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 5, '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': '4940234', 'n_tokens_mistral': 926, 'n_tokens_neox': 912, 'n_words': 194}