<commit_before>package com.sksamuel.elastic4s.searches.queries

import org.elasticsearch.common.xcontent.{NamedXContentRegistry, XContentFactory, XContentType}
import org.elasticsearch.index.query.{MoreLikeThisQueryBuilder, QueryBuilders}

object MoreLikeThisQueryBuilderFn {

  def apply(q: MoreLikeThisQueryDefinition): MoreLikeThisQueryBuilder = {

    val docs = q.likeDocs.map { item =>
      new MoreLikeThisQueryBuilder.Item(item.ref.index, item.ref.`type`, item.ref.id).routing(item.routing.orNull)
    } ++ q.artificialDocs.map { doc =>

      val parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, doc.doc.getBytes)
      parser.close()
      val builder = XContentFactory.jsonBuilder().copyCurrentStructure(parser)

      new MoreLikeThisQueryBuilder.Item(doc.index, doc.`type`, builder).routing(doc.routing.orNull)
    }

    println(docs)

    val builder = QueryBuilders.moreLikeThisQuery(
      q.fields.toArray,
      if (q.likeTexts.isEmpty) null else q.likeTexts.toArray,
      if (docs.isEmpty) null else docs.toArray
    )
<commit_msg>Remove debug print from MoreLikeThisQueryBuilderFn<commit_after>package com.sksamuel.elastic4s.searches.queries

import org.elasticsearch.common.xcontent.{NamedXContentRegistry, XContentFactory, XContentType}
import org.elasticsearch.index.query.{MoreLikeThisQueryBuilder, QueryBuilders}

object MoreLikeThisQueryBuilderFn {

  def apply(q: MoreLikeThisQueryDefinition): MoreLikeThisQueryBuilder = {

    val docs = q.likeDocs.map { item =>
      new MoreLikeThisQueryBuilder.Item(item.ref.index, item.ref.`type`, item.ref.id).routing(item.routing.orNull)
    } ++ q.artificialDocs.map { doc =>

      val parser = XContentFactory.xContent(XContentType.JSON).createParser(NamedXContentRegistry.EMPTY, doc.doc.getBytes)
      parser.close()
      val builder = XContentFactory.jsonBuilder().copyCurrentStructure(parser)

      new MoreLikeThisQueryBuilder.Item(doc.index, doc.`type`, builder).routing(doc.routing.orNull)
    }

    val builder = QueryBuilders.moreLikeThisQuery(
      q.fields.toArray,
      if (q.likeTexts.isEmpty) null else q.likeTexts.toArray,
      if (docs.isEmpty) null else docs.toArray
    )

{'fraction_non_alphanumeric': 0.1055956678700361, 'fraction_numerical': 0.0009025270758122744, 'mean_word_length': 4.584382871536524, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 7, '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': '6749143', 'n_tokens_mistral': 690, 'n_tokens_neox': 687, 'n_words': 107}