<commit_before>/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed 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
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 com.netflix.spinnaker.oort.controllers

import com.netflix.spinnaker.oort.data.aws.Keys
import com.netflix.spinnaker.oort.model.CacheService
import groovy.transform.CompileStatic
import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@CompileStatic
@RestController
class SearchController {

  protected static final Logger log = Logger.getLogger(this)
  static final Integer MAX_PAGE_SIZE = 100

  static String[] cachesToQuery = [
    Keys.Namespace.APPLICATIONS.ns,
    Keys.Namespace.CLUSTERS.ns,
    Keys.Namespace.IMAGES.ns,
    Keys.Namespace.LOAD_BALANCERS.ns,
    Keys.Namespace.SERVER_GROUP_INSTANCES.ns,
    Keys.Namespace.SERVER_GROUPS.ns
  ]

  @Autowired
  CacheService cacheService

  /**
   * Dumb simple search endpoint. Queries against all keys in the cache, returning
   * up to 50 results
   * @param q the phrase to query; words can be separated by spaces, in which case results
   *          must match every word
   * @param pageSize the maximum number of results to return per page; will be capped at 50 if size > 50
   * @param type a {@link com.netflix.spinnaker.oort.data.aws.Keys.Namespace} value, used to only return results of that type
   * @param pageNumber the page number, starting with 1
   * @return a list of matching items in a simple map format with two keys:
   *  { "key":<cache key>, "contents": <JSON map value> }<commit_msg>search loadBalancerServerGroups instead of loadBalancers<commit_after>/*
 * Copyright 2014 Netflix, Inc.
 *
 * Licensed 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
 *
 *    http://www.apache.org/licenses/LICENSE-2.0
 *
 * 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 com.netflix.spinnaker.oort.controllers

import com.netflix.spinnaker.oort.data.aws.Keys
import com.netflix.spinnaker.oort.model.CacheService
import groovy.transform.CompileStatic
import org.apache.log4j.Logger
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.RequestMapping
import org.springframework.web.bind.annotation.RequestParam
import org.springframework.web.bind.annotation.RestController

@CompileStatic
@RestController
class SearchController {

  protected static final Logger log = Logger.getLogger(this)
  static final Integer MAX_PAGE_SIZE = 100

  static String[] cachesToQuery = [
    Keys.Namespace.APPLICATIONS.ns,
    Keys.Namespace.CLUSTERS.ns,
    Keys.Namespace.IMAGES.ns,
    Keys.Namespace.LOAD_BALANCER_SERVER_GROUPS.ns,
    Keys.Namespace.SERVER_GROUP_INSTANCES.ns,
    Keys.Namespace.SERVER_GROUPS.ns
  ]

  @Autowired
  CacheService cacheService

  /**
   * Dumb simple search endpoint. Queries against all keys in the cache, returning
   * up to 50 results
   * @param q the phrase to query; words can be separated by spaces, in which case results
   *          must match every word
   * @param pageSize the maximum number of results to return per page; will be capped at 50 if size > 50
   * @param type a {@link com.netflix.spinnaker.oort.data.aws.Keys.Namespace} value, used to only return results of that type
   * @param pageNumber the page number, starting with 1
   * @return a list of matching items in a simple map format with two keys:
   *  { "key":<cache key>, "contents": <JSON map value> }
{'fraction_non_alphanumeric': 0.07685433422698838, 'fraction_numerical': 0.008489722966934763, 'mean_word_length': 4.070215175537939, 'pattern_counts': {'":': 4, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 2, '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': '5940270', 'n_tokens_mistral': 1282, 'n_tokens_neox': 1226, 'n_words': 454}