<commit_before>package com.sksamuel.elastic4s

import org.elasticsearch.action.search._
import org.elasticsearch.client.Client
import org.elasticsearch.common.unit.TimeValue
import org.elasticsearch.common.xcontent.XContentFactory
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.search.rescore.RescoreBuilder
import org.elasticsearch.search.sort.SortBuilder

import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import scala.language.implicitConversions

/** @author <NAME> */
trait SearchDsl
  extends QueryDsl
  with FilterDsl
  with FacetDsl
  with HighlightDsl
  with ScriptFieldDsl
  with SuggestionDsl
  with IndexesTypesDsl {

  implicit def toRichResponse(resp: SearchResponse): RichSearchResponse = new RichSearchResponse(resp)

  def rescore(query: QueryDefinition): RescoreDefinition = {
    new RescoreDefinition(query)
  }

  def multi(searches: Iterable[SearchDefinition]): MultiSearchDefinition = new MultiSearchDefinition(searches)
  def multi(searches: SearchDefinition*): MultiSearchDefinition = new MultiSearchDefinition(searches)

  implicit object SearchDefinitionExecutable
    extends Executable[SearchDefinition, SearchResponse, SearchResponse] {
    override def apply(c: Client, t: SearchDefinition): Future[SearchResponse] = {
      injectFuture(c.search(t.build, _))
    }
  }

  implicit object MultiSearchDefinitionExecutable
    extends Executable[MultiSearchDefinition, MultiSearchResponse, MultiSearchResponse] {
    override def apply(c: Client, t: MultiSearchDefinition): Future[MultiSearchResponse] = {
      injectFuture(c.multiSearch(t.build, _))
    }
  }

  implicit object SearchDefinitionShow extends Show[SearchDefinition] {
    override def show(f: SearchDefinition): String = f._builder.internalBuilder.toString
  }

  implicit class SearchDefinitionShowOps(f: SearchDefinition) {
    def show: String = SearchDefinitionShow.show(f)
  }
}

class MultiSearchDefinition(searches: Iterable[SearchDefinition]) {
  def build: MultiSearchRequest = {
    val builder = new MultiSearchRequestBuilder(ProxyClients.client)
    searches foreach (builder add _.build)
    builder.request()
  }
}

class RescoreDefinition(query: QueryDefinition) {
  val builder = RescoreBuilder.queryRescorer(query.builder)
  var windowSize = 50

  def window(size: Int): RescoreDefinition = {
    this.windowSize = size
    this
  }

  def originalQueryWeight(weight: Double): RescoreDefinition = {
    builder.setQueryWeight(weight.toFloat)
    this
  }
<commit_msg>made searches a val so multi-search definitions can be deconstructed<commit_after>package com.sksamuel.elastic4s

import org.elasticsearch.action.search._
import org.elasticsearch.client.Client
import org.elasticsearch.common.unit.TimeValue
import org.elasticsearch.common.xcontent.XContentFactory
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.search.rescore.RescoreBuilder
import org.elasticsearch.search.sort.SortBuilder

import scala.concurrent.Future
import scala.concurrent.duration.FiniteDuration
import scala.language.implicitConversions
import compat.Platform.EOL

/** @author <NAME> */
trait SearchDsl
  extends QueryDsl
  with FilterDsl
  with FacetDsl
  with HighlightDsl
  with ScriptFieldDsl
  with SuggestionDsl
  with IndexesTypesDsl {

  implicit def toRichResponse(resp: SearchResponse): RichSearchResponse = new RichSearchResponse(resp)

  def rescore(query: QueryDefinition): RescoreDefinition = {
    new RescoreDefinition(query)
  }

  def multi(searches: Iterable[SearchDefinition]): MultiSearchDefinition = new MultiSearchDefinition(searches)
  def multi(searches: SearchDefinition*): MultiSearchDefinition = new MultiSearchDefinition(searches)

  implicit object SearchDefinitionExecutable
    extends Executable[SearchDefinition, SearchResponse, SearchResponse] {
    override def apply(c: Client, t: SearchDefinition): Future[SearchResponse] = {
      injectFuture(c.search(t.build, _))
    }
  }

  implicit object MultiSearchDefinitionExecutable
    extends Executable[MultiSearchDefinition, MultiSearchResponse, MultiSearchResponse] {
    override def apply(c: Client, t: MultiSearchDefinition): Future[MultiSearchResponse] = {
      injectFuture(c.multiSearch(t.build, _))
    }
  }

  implicit object SearchDefinitionShow extends Show[SearchDefinition] {
    override def show(f: SearchDefinition): String = f._builder.internalBuilder.toString
  }

  implicit class SearchDefinitionShowOps(f: SearchDefinition) {
    def show: String = SearchDefinitionShow.show(f)
  }
}

class MultiSearchDefinition(val searches: Iterable[SearchDefinition]) {
  def build: MultiSearchRequest = {
    val builder = new MultiSearchRequestBuilder(ProxyClients.client)
    searches foreach (builder add _.build)
    builder.request()
  }

  override def toString = searches.mkString("{" + EOL, "," + EOL, "}")
}

class RescoreDefinition(query: QueryDefinition) {
  val builder = RescoreBuilder.queryRescorer(query.builder)
  var windowSize = 50

  def window(size: Int): RescoreDefinition = {
    this.windowSize = size
    this
  }

  def originalQueryWeight(weight: Double): RescoreDefinition = {
    builder.setQueryWeight(weight.toFloat)
    this
  }

{'fraction_non_alphanumeric': 0.08142201834862385, 'fraction_numerical': 0.0011467889908256881, 'mean_word_length': 5.358444714459295, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '4741080', 'n_tokens_mistral': 1448, 'n_tokens_neox': 1455, 'n_words': 322}