<commit_before>import * as types from './types'
import { compareProfilesByVerifications } from '../../utils/index'
import log4js from 'log4js'

const logger = log4js.getLogger('store/search/actions.js')

function updateQuery(query) {
  return {
    type: types.UPDATE_QUERY,
    query
  }
}

function updateResults(query, results) {
  return {
    type: types.UPDATE_RESULTS,
    query,
    results
  }
}

function searchIdentities(query, searchUrl, lookupUrl) {
  return dispatch => {
    let url
    let username
    if (/^[a-z0-9_-]+.id+$/.test(query)) {
      username = query.replace('.id', '')
      url = lookupUrl.replace('{name}', username)
    } else {
      url = searchUrl.replace('{query}', query).replace(' ', '%20')
    }
    return fetch(url)
      .then((response) => response.text())
      .then((responseText) => JSON.parse(responseText))
      .then((responseJson) => {
        let results = []
        if (responseJson.hasOwnProperty('results')) {
          results = responseJson.results
          results.sort(compareProfilesByVerifications)
        } else {
          results.push({<commit_msg>more search action logging #377<commit_after>import * as types from './types'
import { compareProfilesByVerifications } from '../../utils/index'
import log4js from 'log4js'

const logger = log4js.getLogger('store/search/actions.js')

function updateQuery(query) {
  return {
    type: types.UPDATE_QUERY,
    query
  }
}

function updateResults(query, results) {
  return {
    type: types.UPDATE_RESULTS,
    query,
    results
  }
}

function searchIdentities(query, searchUrl, lookupUrl) {
  logger.trace(`searchIdentities: query: "${query}" searchUrl: ${searchUrl} ${lookupUrl}`)
  return dispatch => {
    let url
    let username
    if (/^[a-z0-9_-]+.id+$/.test(query)) {
      logger.debug(`searchIdentities:
        "${query}": looks like a '.id' Blockstack ID. Let's look it up...`)
      username = query.replace('.id', '')
      url = lookupUrl.replace('{name}', username)
    } else {
      logger.debug(`"${query}": isn't a '.id' Blockstack ID. Let's search...`)
      url = searchUrl.replace('{query}', query).replace(' ', '%20')
    }
    return fetch(url)
      .then((response) => response.text())
      .then((responseText) => JSON.parse(responseText))
      .then((responseJson) => {
        let results = []
        if (responseJson.hasOwnProperty('results')) {
          logger.debug(`"${query}" produced multiple results. Sorting by verification level...`)
          results = responseJson.results
          results.sort(compareProfilesByVerifications)
        } else {
          logger.debug(`Found an exact match for "${query}"`)
          results.push({
{'fraction_non_alphanumeric': 0.1542454579162032, 'fraction_numerical': 0.006303299962921765, 'mean_word_length': 2.9911242603550297, 'pattern_counts': {'":': 2, '<': 3, '<?xml version=': 0, '>': 11, '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': '5424442', 'n_tokens_mistral': 809, 'n_tokens_neox': 802, 'n_words': 179}