<commit_before>package com.sksamuel.elastic4s

import org.elasticsearch.action.search._
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.search.sort.SortBuilder
import org.elasticsearch.search.rescore.RescoreBuilder

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

  @deprecated("use select or search", "1.0")
  def find = new SearchExpectsIndex

  def select: SearchExpectsIndex = search
  def select(indexes: String*): SearchDefinition = search(indexes: _*)
  def search: SearchExpectsIndex = new SearchExpectsIndex
  def search(indexes: String*): SearchDefinition = new SearchDefinition(IndexesTypes(indexes))
  class SearchExpectsIndex {
    def in(indexes: String*): SearchDefinition = in(IndexesTypes(indexes))
    def in(tuple: (String, String)): SearchDefinition = in(IndexesTypes(tuple))
    def in(indexesTypes: IndexesTypes): SearchDefinition = new SearchDefinition(indexesTypes)
  }

  class MultiSearchDefinition(searches: Iterable[SearchDefinition])
    extends RequestDefinition(MultiSearchAction.INSTANCE) {
    def build = {
      val builder = new MultiSearchRequestBuilder(null)
      searches foreach (builder add _.build)
      builder.request()
    }
  }

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

  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
    }

    def rescoreQueryWeight(weight: Double): RescoreDefinition = {
      builder.setRescoreQueryWeight(weight.toFloat)
      this
    }

    def scoreMode(scoreMode: String): RescoreDefinition = {
      builder.setScoreMode(scoreMode)
      this
    }
  }

  class SearchDefinition(indexesTypes: IndexesTypes) extends RequestDefinition(SearchAction.INSTANCE) {

    // TODO Discuss: temporarily open to pass tests
    private[elastic4s] val _builder = {
      new SearchRequestBuilder(null)
        .setIndices(indexesTypes.indexes: _*)
        .setTypes(indexesTypes.types: _*)
    }
    def build = _builder.request()

    /**
     * Adds a single string query to this search
     *
     * @param string the query string
     *
     * @return this
     */
    def query(string: String): SearchDefinition = query(new StringQueryDefinition(string))
    def query(block: => QueryDefinition): SearchDefinition = query2(block.builder)
    def query2(block: => QueryBuilder): SearchDefinition = {
      _builder.setQuery(block)
      this
    }
    def bool(block: => BoolQueryDefinition): SearchDefinition = {
      _builder.setQuery(block.builder)
      this
    }

    def filter(block: => FilterDefinition): SearchDefinition = {
      _builder.setPostFilter(block.builder)
      this
    }

    def facets(iterable: Iterable[FacetDefinition]): SearchDefinition = {
      iterable.foreach(facet => _builder.addFacet(facet.builder))<commit_msg>#74 Opened builder for tests<commit_after>package com.sksamuel.elastic4s

import org.elasticsearch.action.search._
import org.elasticsearch.index.query.QueryBuilder
import org.elasticsearch.search.sort.SortBuilder
import org.elasticsearch.search.rescore.RescoreBuilder

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

  @deprecated("use select or search", "1.0")
  def find = new SearchExpectsIndex

  def select: SearchExpectsIndex = search
  def select(indexes: String*): SearchDefinition = search(indexes: _*)
  def search: SearchExpectsIndex = new SearchExpectsIndex
  def search(indexes: String*): SearchDefinition = new SearchDefinition(IndexesTypes(indexes))
  class SearchExpectsIndex {
    def in(indexes: String*): SearchDefinition = in(IndexesTypes(indexes))
    def in(tuple: (String, String)): SearchDefinition = in(IndexesTypes(tuple))
    def in(indexesTypes: IndexesTypes): SearchDefinition = new SearchDefinition(indexesTypes)
  }

  class MultiSearchDefinition(searches: Iterable[SearchDefinition])
    extends RequestDefinition(MultiSearchAction.INSTANCE) {
    def build = {
      val builder = new MultiSearchRequestBuilder(null)
      searches foreach (builder add _.build)
      builder.request()
    }
  }

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

  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
    }

    def rescoreQueryWeight(weight: Double): RescoreDefinition = {
      builder.setRescoreQueryWeight(weight.toFloat)
      this
    }

    def scoreMode(scoreMode: String): RescoreDefinition = {
      builder.setScoreMode(scoreMode)
      this
    }
  }

  class SearchDefinition(indexesTypes: IndexesTypes) extends RequestDefinition(SearchAction.INSTANCE) {

    val _builder = {
      new SearchRequestBuilder(null)
        .setIndices(indexesTypes.indexes: _*)
        .setTypes(indexesTypes.types: _*)
    }
    def build = _builder.request()

    /**
     * Adds a single string query to this search
     *
     * @param string the query string
     *
     * @return this
     */
    def query(string: String): SearchDefinition = query(new StringQueryDefinition(string))
    def query(block: => QueryDefinition): SearchDefinition = query2(block.builder)
    def query2(block: => QueryBuilder): SearchDefinition = {
      _builder.setQuery(block)
      this
    }
    def bool(block: => BoolQueryDefinition): SearchDefinition = {
      _builder.setQuery(block.builder)
      this
    }

    def filter(block: => FilterDefinition): SearchDefinition = {
      _builder.setPostFilter(block.builder)
      this
    }

    def facets(iterable: Iterable[FacetDefinition]): SearchDefinition = {
      iterable.foreach(facet => _builder.addFacet(facet.builder))
{'fraction_non_alphanumeric': 0.09233176838810642, 'fraction_numerical': 0.0026604068857589984, 'mean_word_length': 3.8637747336377473, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 15, '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': '7245058', 'n_tokens_mistral': 1821, 'n_tokens_neox': 1804, 'n_words': 405}