<commit_before>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use
 * this file except in compliance with the License. You may obtain a copy of the License at the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apereo.portal.portlets.search.google;

import com.fasterxml.jackson.databind.JsonNode;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletRequest;
import org.apereo.portal.portlets.search.IPortalSearchService;
import org.apereo.portal.search.SearchRequest;
import org.apereo.portal.search.SearchResult;
import org.apereo.portal.search.SearchResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.client.RestOperations;

/**
 * Service for searching using the Google Custom-Search API:
 * https://developers.google.com/custom-search/v1/overview
 */
public class GoogleCustomSearchService implements IPortalSearchService {
    public static final String QUERY_PARAM = "q";
    public static final String VERSION_PARAM = "v";
    public static final String USER_IP_PARAM = "userip";
    public static final String RESULT_SIZE_PARAM = "rsz";
    public static final String START_PARAM = "start";
    public static final String CUSTOM_SEARCH_PARAM = "cx";
    public static final String VERSION = "1.0";

    private static final String BASE_SEARCH_URL =
            "http://ajax.googleapis.com/ajax/services/search/web?"
                    + QUERY_PARAM
                    + "={"
                    + QUERY_PARAM
                    + "}&"
                    + VERSION_PARAM
                    + "={"
                    + VERSION_PARAM
                    + "}&"
                    + USER_IP_PARAM
                    + "={"
                    + USER_IP_PARAM
                    + "}&"
                    + RESULT_SIZE_PARAM
                    + "={"
                    + RESULT_SIZE_PARAM
                    + "}&"
                    + CUSTOM_SEARCH_PARAM
                    + "={"
                    + CUSTOM_SEARCH_PARAM
                    + "}";

    private String resultSize = "large";
    private String customSearchId;
<commit_msg>WIP: Review of new Google URL parameters.'<commit_after>/**
 * Licensed to Apereo under one or more contributor license agreements. See the NOTICE file
 * distributed with this work for additional information regarding copyright ownership. Apereo
 * licenses this file to you under the Apache License, Version 2.0 (the "License"); you may not use
 * this file except in compliance with the License. You may obtain a copy of the License at the
 * following location:
 *
 * <p>http://www.apache.org/licenses/LICENSE-2.0
 *
 * <p>Unless required by applicable law or agreed to in writing, software distributed under the
 * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either
 * express or implied. See the License for the specific language governing permissions and
 * limitations under the License.
 */
package org.apereo.portal.portlets.search.google;

import com.fasterxml.jackson.databind.JsonNode;
import java.util.Iterator;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;
import javax.portlet.PortletRequest;
import org.apereo.portal.portlets.search.IPortalSearchService;
import org.apereo.portal.search.SearchRequest;
import org.apereo.portal.search.SearchResult;
import org.apereo.portal.search.SearchResults;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.web.client.RestOperations;

/**
 * Service for searching using the Google Custom-Search API:
 * https://developers.google.com/custom-search/v1/overview
 */
public class GoogleCustomSearchService implements IPortalSearchService {
    public static final String QUERY_PARAM = "q";
    public static final String VERSION_PARAM = "v"; // in new url
    public static final String USER_IP_PARAM = "userip"; // remove
    public static final String RESULT_SIZE_PARAM = "rsz"; // num
    public static final String START_PARAM = "start";
    public static final String CUSTOM_SEARCH_PARAM = "cx";
    public static final String VERSION = "1.0";

    private static final String BASE_SEARCH_URL =
            "http://ajax.googleapis.com/ajax/services/search/web?"
                    + QUERY_PARAM
                    + "={"
                    + QUERY_PARAM
                    + "}&"
                    + VERSION_PARAM
                    + "={"
                    + VERSION_PARAM
                    + "}&"
                    + USER_IP_PARAM
                    + "={"
                    + USER_IP_PARAM
                    + "}&"
                    + RESULT_SIZE_PARAM
                    + "={"
                    + RESULT_SIZE_PARAM
                    + "}&"
                    + CUSTOM_SEARCH_PARAM
                    + "={"
                    + CUSTOM_SEARCH_PARAM
                    + "}";

    private String resultSize = "large";
    private String customSearchId;

{'fraction_non_alphanumeric': 0.08503636993418774, 'fraction_numerical': 0.0024246622791825423, 'mean_word_length': 2.421208530805687, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 7, 'https://': 2, 'lorem ipsum': 0, 'www.': 2, 'xml': 2}, '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': '4675374', 'n_tokens_mistral': 1536, 'n_tokens_neox': 1477, 'n_words': 447}