<commit_before>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.jcommune.web.controller;

import org.jtalks.jcommune.model.entity.Topic;
import org.jtalks.jcommune.service.LastReadPostService;
import org.jtalks.jcommune.service.TopicFetchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * The controller for the full-text search topics.
 *
 * @author <NAME>
 */
@Controller
public class TopicSearchController {
    /**
     * The name attribute for the uri.
     */
    public static final String URI_ATTRIBUTE_NAME = "uri";
    /**
     * The name attribute for {@link Page}, that contains info for one page
     * of search result.
     */
    public static final String SEARCH_RESULT_ATTRIBUTE_NAME = "searchResultPage";
    /**
     * The name attribute for the search text.
     */
    public static final String SEARCH_TEXT_ATTRIBUTE_NAME = "searchText";

    private static final String SEARCH_RESULT_VIEW_NAME = "topic/searchResult";

    private TopicFetchService topicSearchService;
    
    private LastReadPostService lastReadPostService;

    /**
     * Constructor for controller instantiating, dependencies injected via autowiring.
     *
     * @param topicSearchService {@link TopicFetchService} to perform actual search
     * @param lastReadPostService {@link LastReadPostService} to fill info about topic updates  
     */
    @Autowired
    public TopicSearchController(TopicFetchService topicSearchService,
                                 LastReadPostService lastReadPostService) {
        this.topicSearchService = topicSearchService;
        this.lastReadPostService = lastReadPostService;
    }

    /**
     * This method performs a indexing the data from the database.
     */
    @RequestMapping(value = "/search/index/rebuild")
    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    public void rebuildIndexes() {
        topicSearchService.rebuildSearchIndex();
    }

    /**
     * Full-text search for topics. It needed to start the search.
     *
     * @param searchText search text
     * @return redirect to the answer page
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public ModelAndView initSearch(@RequestParam(value = "text", required = true) String searchText,
                                   @RequestParam(value = "page", defaultValue = "1", required = false) String page) {
        Page<Topic> searchResultPage = topicSearchService.searchByTitleAndContent(searchText, page);
        lastReadPostService.fillLastReadPostForTopics(searchResultPage.getContent());
        return new ModelAndView(SEARCH_RESULT_VIEW_NAME).
                addObject(SEARCH_RESULT_ATTRIBUTE_NAME, searchResultPage).
                addObject(SEARCH_TEXT_ATTRIBUTE_NAME, searchText);
    }
}<commit_msg>#JC-1473 - "text" parameter for the search request has become optional<commit_after>/**
 * Copyright (C) 2011  JTalks.org Team
 * This library is free software; you can redistribute it and/or
 * modify it under the terms of the GNU Lesser General Public
 * License as published by the Free Software Foundation; either
 * version 2.1 of the License, or (at your option) any later version.
 * This library is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
 * Lesser General Public License for more details.
 * You should have received a copy of the GNU Lesser General Public
 * License along with this library; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
 */
package org.jtalks.jcommune.web.controller;

import org.jtalks.jcommune.model.entity.Topic;
import org.jtalks.jcommune.service.LastReadPostService;
import org.jtalks.jcommune.service.TopicFetchService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.domain.Page;
import org.springframework.http.HttpStatus;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

/**
 * The controller for the full-text search topics.
 *
 * @author <NAME>
 */
@Controller
public class TopicSearchController {
    /**
     * The name attribute for the uri.
     */
    public static final String URI_ATTRIBUTE_NAME = "uri";
    /**
     * The name attribute for {@link Page}, that contains info for one page
     * of search result.
     */
    public static final String SEARCH_RESULT_ATTRIBUTE_NAME = "searchResultPage";
    /**
     * The name attribute for the search text.
     */
    public static final String SEARCH_TEXT_ATTRIBUTE_NAME = "searchText";

    private static final String SEARCH_RESULT_VIEW_NAME = "topic/searchResult";

    private TopicFetchService topicSearchService;
    
    private LastReadPostService lastReadPostService;

    /**
     * Constructor for controller instantiating, dependencies injected via autowiring.
     *
     * @param topicSearchService {@link TopicFetchService} to perform actual search
     * @param lastReadPostService {@link LastReadPostService} to fill info about topic updates  
     */
    @Autowired
    public TopicSearchController(TopicFetchService topicSearchService,
                                 LastReadPostService lastReadPostService) {
        this.topicSearchService = topicSearchService;
        this.lastReadPostService = lastReadPostService;
    }

    /**
     * This method performs a indexing the data from the database.
     */
    @RequestMapping(value = "/search/index/rebuild")
    @ResponseStatus(value = HttpStatus.NO_CONTENT)
    public void rebuildIndexes() {
        topicSearchService.rebuildSearchIndex();
    }

    /**
     * Full-text search for topics. It needed to start the search.
     *
     * @param searchText search text
     * @return redirect to the answer page
     */
    @RequestMapping(value = "/search", method = RequestMethod.GET)
    public ModelAndView initSearch(@RequestParam(value = "text", defaultValue = "", required = false) String searchText,
                                   @RequestParam(value = "page", defaultValue = "1", required = false) String page) {
        Page<Topic> searchResultPage = topicSearchService.searchByTitleAndContent(searchText, page);
        lastReadPostService.fillLastReadPostForTopics(searchResultPage.getContent());
        return new ModelAndView(SEARCH_RESULT_VIEW_NAME).
                addObject(SEARCH_RESULT_ATTRIBUTE_NAME, searchResultPage).
                addObject(SEARCH_TEXT_ATTRIBUTE_NAME, searchText);
    }
}
{'fraction_non_alphanumeric': 0.07754675035961815, 'fraction_numerical': 0.005230809467765137, 'mean_word_length': 3.5041224970553593, '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': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '1897149', 'n_tokens_mistral': 2004, 'n_tokens_neox': 1965, 'n_words': 648}