<commit_before>import {State, ArrayState, ObjectState, ValueState} from "./state/State"
import {ImmutableQuery} from "./query/ImmutableQuery";
import {Accessor} from "./accessors/Accessor"
import {SearchkitManager} from "./SearchkitManager"

export enum SearchType {
  count,
  query_then_fetch,
  scan
}

export class Searcher {
  accessors: Array<Accessor<any>>
  query: ImmutableQuery
  queryHasChanged: boolean
  results: any
  searchkitManager:SearchkitManager
  search_type:SearchType
  constructor() {
    this.accessors = []
    this.search_type = SearchType.count
    this.query = new ImmutableQuery()
  }

  setSearchkitManager(searchkitManager){
    this.searchkitManager = searchkitManager
  }

  hasFilters(){
    return this.query && this.query.hasFilters()
  }

  addAccessor(accessor: Accessor<any>) {
    this.accessors.push(accessor)
    accessor.setSearcher(this)
  }
  buildQuery(query) {
    _.each(this.accessors, (accessor) => {
      query = accessor.buildOwnQuery(query)
    })
    this.queryHasChanged = ImmutableQuery.areQueriesDifferent(
      this.query, query)
    this.query = query
  }
  getCommandAndQuery(){
    return [
      {index:this.searchkitManager.index, search_type:SearchType[this.search_type]},
      this.query.getJSON()
    ]
  }
  getResults() {
    return this.results
  }
  setResults(results) {
    this.results = results
  }
}<commit_msg>add configurable index<commit_after>import {State, ArrayState, ObjectState, ValueState} from "./state/State"
import {ImmutableQuery} from "./query/ImmutableQuery";
import {Accessor} from "./accessors/Accessor"
import {SearchkitManager} from "./SearchkitManager"

export enum SearchType {
  count,
  query_then_fetch,
  scan
}

export class Searcher {
  accessors: Array<Accessor<any>>
  query: ImmutableQuery
  queryHasChanged: boolean
  results: any
  searchkitManager:SearchkitManager
  search_type:SearchType
  index:string
  constructor() {
    this.accessors = []
    this.search_type = SearchType.count
    this.query = new ImmutableQuery()
  }

  setSearchkitManager(searchkitManager){
    this.searchkitManager = searchkitManager
  }

  setIndex(index){
    this.index = index
  }
  getIndex(){
    this.index || this.searchkitManager.index
  }

  hasFilters(){
    return this.query && this.query.hasFilters()
  }

  addAccessor(accessor: Accessor<any>) {
    this.accessors.push(accessor)
    accessor.setSearcher(this)
  }
  buildQuery(query) {
    _.each(this.accessors, (accessor) => {
      query = accessor.buildOwnQuery(query)
    })
    this.queryHasChanged = ImmutableQuery.areQueriesDifferent(
      this.query, query)
    this.query = query
  }
  getCommandAndQuery(){
    return [
      {index:this.getIndex(), search_type:SearchType[this.search_type]},
      this.query.getJSON()
    ]
  }
  getResults() {
    return this.results
  }
  setResults(results) {
    this.results = results
  }
}
{'fraction_non_alphanumeric': 0.11333103685842232, 'fraction_numerical': 0.0, 'mean_word_length': 3.80794701986755, 'pattern_counts': {'":': 0, '<': 9, '<?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': '7619161', 'n_tokens_mistral': 921, 'n_tokens_neox': 916, 'n_words': 165}