<commit_before>import {SearchResponse} from 'elasticsearch';
import {Action} from 'redux';
import {combineEpics, Epic} from 'redux-observable';
import {ajax} from 'rxjs/observable/dom/ajax';
import {empty} from 'rxjs/observable/empty';
import {of } from 'rxjs/observable/of';
import {catchError} from 'rxjs/operators/catchError';
import {map} from 'rxjs/operators/map';
import {switchMap} from 'rxjs/operators/switchMap';

import * as search from '../actions/search';
import {EpicDependencies} from '../epics';
import {State as GlobalState} from '../reducers';
import {Player} from '../shared/service/api';

export const search$: Epic<Action, GlobalState, EpicDependencies> =
    (action$, store, deps) =>
        action$.ofType(search.SEARCH_REQUEST)
            .pipe(switchMap((action: search.SearchRequestAction) => {
              const {query} = action.payload;
              if (!query) {
                return empty();
              }
              const url = `${process.env.REACT_APP_API_ROOT}/search`;
              return ajax
                  .getJSON<SearchResponse<Player>>(
                      `${url}?query=${encodeURIComponent(query)}`)
                  .pipe(
                      map(res => res.hits.hits.map(hit => hit._source)),
                      map(players => search.searchSuccess(players)),<commit_msg>fix(ui) patch hit._id into player search results<commit_after>import {SearchResponse} from 'elasticsearch';
import {Action} from 'redux';
import {combineEpics, Epic} from 'redux-observable';
import {ajax} from 'rxjs/observable/dom/ajax';
import {empty} from 'rxjs/observable/empty';
import {of } from 'rxjs/observable/of';
import {catchError} from 'rxjs/operators/catchError';
import {map} from 'rxjs/operators/map';
import {switchMap} from 'rxjs/operators/switchMap';

import * as search from '../actions/search';
import {EpicDependencies} from '../epics';
import {State as GlobalState} from '../reducers';
import {Player} from '../shared/service/api';

export const search$: Epic<Action, GlobalState, EpicDependencies> =
    (action$, store, deps) =>
        action$.ofType(search.SEARCH_REQUEST)
            .pipe(switchMap((action: search.SearchRequestAction) => {
              const {query} = action.payload;
              if (!query) {
                return empty();
              }
              const url = `${process.env.REACT_APP_API_ROOT}/search`;
              return ajax
                  .getJSON<SearchResponse<Player>>(
                      `${url}?query=${encodeURIComponent(query)}`)
                  .pipe(
                      map(res => res.hits.hits.map(hit => {
                        // Search results strip the player.id and
                        // surface it in hit._id
                        return {
                          ...hit._source,
                          id: hit._id,
                        } as Player;
                      })),
                      map(players => search.searchSuccess(players)),
{'fraction_non_alphanumeric': 0.13482770157243226, 'fraction_numerical': 0.0, 'mean_word_length': 2.2324324324324323, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 19, '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': '4893005', 'n_tokens_mistral': 837, 'n_tokens_neox': 811, 'n_words': 196}