<commit_before># encoding: utf-8

module XapianDb
  module Adapters

    # base class for all adapters.
    # This adapter does the following:
    # - adds the class method <code>search(expression)</code> to an indexed class
    # @author <NAME>

     class BaseAdapter

       class << self

         # Implement the class helper methods
         # @param [Class] klass The class to add the helper methods to
         def add_class_helper_methods_to(klass)

           klass.class_eval do

             # Add a method to search models of this class
             # Options:
             # - :order          (Array<Symbol>) Accepts an array of attribute names for sorting
             # - :sort_decending (Boolean)       Allows to reverse the sorting
             define_singleton_method(:search) do |expression, options={}|
               options = {:sort_decending => false}.merge options
               class_scope = "indexed_class:#{klass.name.downcase}"

               if options[:order]
                 attr_names   = [options[:order]].flatten
                 sort_indices = []
                 blueprint    = XapianDb::DocumentBlueprint.blueprint_for klass
                 sort_indices = attr_names.map {|attr_name| blueprint.value_index_for(attr_name)}
               else
                 sort_indices = nil
               end
               result = XapianDb.database.search "#{class_scope} and (#{expression})", :sort_indices => sort_indices, :sort_decending => options[:sort_decending]

               # Remove the class scope from the spelling suggestion (if any)
               unless result.spelling_suggestion.empty?
                 scope_length = "#{class_scope} and (".size
                 result.spelling_suggestion = result.spelling_suggestion.slice scope_length..-2
               end
               result
             end<commit_msg>class search method now passes all options to database.search<commit_after># encoding: utf-8

module XapianDb
  module Adapters

    # base class for all adapters.
    # This adapter does the following:
    # - adds the class method <code>search(expression)</code> to an indexed class
    # @author <NAME>

     class BaseAdapter

       class << self

         # Implement the class helper methods
         # @param [Class] klass The class to add the helper methods to
         def add_class_helper_methods_to(klass)

           klass.class_eval do

             # Add a method to search models of this class
             # Options:
             # - :order          (Array<Symbol>) Accepts an array of attribute names for sorting
             # - :sort_decending (Boolean)       Allows to reverse the sorting
             define_singleton_method(:search) do |expression, options={}|
               options = {:sort_decending => false}.merge options
               class_scope = "indexed_class:#{klass.name.downcase}"

               if options[:order]
                 attr_names             = [options[:order]].flatten
                 blueprint              = XapianDb::DocumentBlueprint.blueprint_for klass
                 sort_indices           = attr_names.map {|attr_name| blueprint.value_index_for(attr_name)}
                 options[:sort_indices] = attr_names.map {|attr_name| blueprint.value_index_for(attr_name)}
               end
               result = XapianDb.database.search "#{class_scope} and (#{expression})", options

               # Remove the class scope from the spelling suggestion (if any)
               unless result.spelling_suggestion.empty?
                 scope_length = "#{class_scope} and (".size
                 result.spelling_suggestion = result.spelling_suggestion.slice scope_length..-2
               end
               result
             end
{'fraction_non_alphanumeric': 0.07706666666666667, 'fraction_numerical': 0.0010666666666666667, 'mean_word_length': 1.9558707643814026, 'pattern_counts': {'":': 0, '<': 15, '<?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': '7234148', 'n_tokens_mistral': 957, 'n_tokens_neox': 932, 'n_words': 276}