<commit_before>if defined?(EffectiveDatatables)
  module Effective
    module Datatables
      class QbSyncs < Effective::Datatable
        datatable do
          default_order :created_at, :desc

          table_column :created_at
          table_column :state, filter: { values: QbTicket::STATES }

          array_column :num_orders, visible: false do |qb_ticket|
            qb_ticket.qb_requests.length
          end

          array_column :orders do |qb_ticket|
            qb_ticket.qb_requests.select { |qb_request| qb_request.order.present? }
              .map { |qb_request| link_to "##{qb_request.order.to_param}", effective_orders.admin_order_path(qb_request.order) }
              .join('<br>').html_safe
          end

          table_column :actions, sortable: false, filter: false, partial: 'admin/qb_syncs/actions', partial_local: :qb_sync
        end

        def collection
          Effective::QbTicket.includes(qb_requests: :order)
        end
      end
    end
  end
end<commit_msg>Improve searching of orders<commit_after>if defined?(EffectiveDatatables)
  module Effective
    module Datatables
      class QbSyncs < Effective::Datatable
        datatable do
          default_order :created_at, :desc

          table_column :created_at
          table_column :state, filter: { values: QbTicket::STATES }

          array_column :num_orders, visible: false do |qb_ticket|
            qb_ticket.qb_requests.length
          end

          table_column :orders, sortable: false, as: :obfuscated_id do |qb_ticket|
            qb_ticket.qb_requests.select { |qb_request| qb_request.order.present? }
              .map { |qb_request| link_to "##{qb_request.order.to_param}", effective_orders.admin_order_path(qb_request.order) }
              .join('<br>').html_safe
          end

          actions_column partial: 'admin/qb_syncs/actions', partial_local: :qb_sync
        end

        def collection
          Effective::QbTicket.includes(qb_requests: :order)
        end

        def search_column(collection, table_column, search_term, sql_column)
          if table_column[:name] == 'orders'
            order = Effective::Order.where(id: search_term).first

            if order.present?
              collection.where(id: Effective::QbRequest.where(order_id: order.id).pluck(:qb_ticket_id))
            else
              collection.none
            end
          else
            super
          end
        end

      end
    end
  end
end
{'fraction_non_alphanumeric': 0.0854251012145749, 'fraction_numerical': 0.0, 'mean_word_length': 2.2990654205607477, 'pattern_counts': {'":': 0, '<': 7, '<?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': '4321875', 'n_tokens_mistral': 764, 'n_tokens_neox': 736, 'n_words': 150}