<commit_before>require "riddle"

module Mongoid
  module Giza
    ##
    # Executes queries on Sphinx
    class Search
      attr_reader :client
      ##
      # Creates a new search
      #
      # @param host [String] the host address of sphinxd
      # @param port [Fixnum] the TCP port of sphinxd
      def initialize(host, port)
        @client = Riddle::Client.new(host, port)
      end
      ##
      # Retrieves the indexes in which this search will be performed on.
      # "*" is the default, which means all indexes
      #
      # @return [String] a string of all indexes separated by spaces
      def indexes
        @indexes ||= "*"
      end
      ##
      # Sets the search criteria on full-text fields
      #
      # @param query [String] a sphinx query string based on the current {http://sphinxsearch.com/docs/current.html#matching-modes matching mode}
      def fulltext(query)
        @client.append_query(query, indexes)
      end
      ##
      # Sets a filter based on an attribute.
      # Only documents that the attribute value matches will be returned from the search
      #
      # @param attribute [Symbol] the attribute name to set the filter
      # @param value [Fixnum, Float, Range] the value (or values) that the attribute must match
      def with(attribute, value)
        @client.filters << Riddle::Client::Filter.new(attribute.to_s, value, false)
      end
      ##
      # Excludes from the search documents that the attribute value matches<commit_msg>Initialize the indexes instance variable on object creation and define an accessor for it<commit_after>require "riddle"

module Mongoid
  module Giza
    ##
    # Executes queries on Sphinx
    class Search
      attr_accessor :indexes
      attr_reader :client
      ##
      # Creates a new search
      #
      # @param host [String] the host address of sphinxd
      # @param port [Fixnum] the TCP port of sphinxd
      # @param indexes [String] an optional string define the indexes that the search will run on.
      #   Defaults to "*" which means all indexes
      def initialize(host, port, indexes="*")
        @client = Riddle::Client.new(host, port)
        @indexes = indexes || "*"
      end
      ##
      # Sets the search criteria on full-text fields
      #
      # @param query [String] a sphinx query string based on the current {http://sphinxsearch.com/docs/current.html#matching-modes matching mode}
      def fulltext(query)
        @client.append_query(query, indexes)
      end
      ##
      # Sets a filter based on an attribute.
      # Only documents that the attribute value matches will be returned from the search
      #
      # @param attribute [Symbol] the attribute name to set the filter
      # @param value [Fixnum, Float, Range] the value (or values) that the attribute must match
      def with(attribute, value)
        @client.filters << Riddle::Client::Filter.new(attribute.to_s, value, false)
      end
      ##
      # Excludes from the search documents that the attribute value matches
{'fraction_non_alphanumeric': 0.07829534192269574, 'fraction_numerical': 0.0, 'mean_word_length': 2.5291375291375293, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 3, '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': '4792790', 'n_tokens_mistral': 825, 'n_tokens_neox': 804, 'n_words': 328}