<commit_before>import { createSelector } from 'reselect';
import {
  SearchResult,
  SearchResults,
  HitBlockMap,
  RequesterBlockMap,
  SortingOption,
  AttributeWeights,
  RequesterId
} from '../types';
import {
  filterBelowTOThreshold,
  attributeWeightsSelector
} from './turkopticon';
import { sortBy } from '../utils/sorting';
import {
  searchResultSelector,
  hitBlocklistSelector,
  requesterBlocklistSelector,
  sortOptionSelector
} from './index';
import { noTurkopticon } from '../utils/turkopticon';
import { List } from 'immutable';

const selectGroupId = (hit: SearchResult) => hit.groupId;

export const resultsLengthSelector = createSelector(
  [searchResultSelector],
  (searchResults: SearchResults) => searchResults.size
);

const hideBlockedHits = createSelector(
  [searchResultSelector, hitBlocklistSelector],
  (hits: SearchResults, blockedHits: HitBlockMap) =>
    hits.filter(
      (hit: SearchResult) => !blockedHits.get(hit.groupId)
    ) as SearchResults
);

export const hideBlockedRequesters = createSelector(
  [searchResultSelector, requesterBlocklistSelector],
  (hits: SearchResults, blockedRequesters: RequesterBlockMap) =>
    hits.filter(
      (hit: SearchResult) => !blockedRequesters.get(hit.requester.id)
    ) as SearchResults
);

const hideBlockedRequestersAndHits = createSelector(
  [hideBlockedHits, requesterBlocklistSelector],
  (
    resultsFilteredByBlockedIds: SearchResults,
    blockedRequesters: RequesterBlockMap
  ) =>
    resultsFilteredByBlockedIds.filter(
      (result: SearchResult) => !blockedRequesters.get(result.requester.id)
    ) as SearchResults
);

const filteredAndSortedResults = createSelector(
  [
    hideBlockedRequestersAndHits,
    filterBelowTOThreshold,
    sortOptionSelector,
    attributeWeightsSelector
  ],
  (
    hits: SearchResults,
    aboveThreshold: SearchResults,
    sortingOption: SortingOption,
    weights: AttributeWeights
  ) =>
    hits
      .filter((hit: SearchResult) => aboveThreshold.has(hit.groupId))
      .sort(sortBy(sortingOption, weights))
  // .sort(unreadFirst) as SearchResults
);

export const newResults = createSelector(<commit_msg>Use .has instead of boolean coerced .get.<commit_after>import { createSelector } from 'reselect';
import {
  SearchResult,
  SearchResults,
  HitBlockMap,
  RequesterBlockMap,
  SortingOption,
  AttributeWeights,
  RequesterId
} from '../types';
import {
  filterBelowTOThreshold,
  attributeWeightsSelector
} from './turkopticon';
import { sortBy } from '../utils/sorting';
import {
  searchResultSelector,
  hitBlocklistSelector,
  requesterBlocklistSelector,
  sortOptionSelector
} from './index';
import { noTurkopticon } from '../utils/turkopticon';
import { List } from 'immutable';

const selectGroupId = (hit: SearchResult) => hit.groupId;

export const resultsLengthSelector = createSelector(
  [searchResultSelector],
  (searchResults: SearchResults) => searchResults.size
);

const hideBlockedHits = createSelector(
  [searchResultSelector, hitBlocklistSelector],
  (hits: SearchResults, blockedHits: HitBlockMap) =>
    hits.filter(
      (hit: SearchResult) => !blockedHits.has(hit.groupId)
    ) as SearchResults
);

export const hideBlockedRequesters = createSelector(
  [searchResultSelector, requesterBlocklistSelector],
  (hits: SearchResults, blockedRequesters: RequesterBlockMap) =>
    hits.filter(
      (hit: SearchResult) => !blockedRequesters.has(hit.requester.id)
    ) as SearchResults
);

const hideBlockedRequestersAndHits = createSelector(
  [hideBlockedHits, requesterBlocklistSelector],
  (
    resultsFilteredByBlockedIds: SearchResults,
    blockedRequesters: RequesterBlockMap
  ) =>
    resultsFilteredByBlockedIds.filter(
      (result: SearchResult) => !blockedRequesters.has(result.requester.id)
    ) as SearchResults
);

const filteredAndSortedResults = createSelector(
  [
    hideBlockedRequestersAndHits,
    filterBelowTOThreshold,
    sortOptionSelector,
    attributeWeightsSelector
  ],
  (
    hits: SearchResults,
    aboveThreshold: SearchResults,
    sortingOption: SortingOption,
    weights: AttributeWeights
  ) =>
    hits
      .filter((hit: SearchResult) => aboveThreshold.has(hit.groupId))
      .sort(sortBy(sortingOption, weights))
  // .sort(unreadFirst) as SearchResults
);

export const newResults = createSelector(
{'fraction_non_alphanumeric': 0.10046189376443418, 'fraction_numerical': 0.0, 'mean_word_length': 4.868563685636857, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 23, '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': '7185889', 'n_tokens_mistral': 1305, 'n_tokens_neox': 1307, 'n_words': 255}