Module: MiniSearch

Defined in:
lib/mini_search.rb,
lib/mini_search/tf.rb,
lib/mini_search/idf.rb,
lib/mini_search/bm_25.rb,
lib/mini_search/version.rb,
lib/mini_search/pipeline.rb,
lib/mini_search/strip_filter.rb,
lib/mini_search/inverted_index.rb,
lib/mini_search/stemmer_filter.rb,
lib/mini_search/downcase_filter.rb,
lib/mini_search/ngram_tokenizer.rb,
lib/mini_search/synonyms_filter.rb,
lib/mini_search/stop_words_filter.rb,
lib/mini_search/compound_tokenizer.rb,
lib/mini_search/stemmer/portuguese.rb,
lib/mini_search/inverted_index_spec.rb,
lib/mini_search/remove_punctuation_filter.rb,
lib/mini_search/language_support/portuguese.rb,
lib/mini_search/standard_whitespace_tokenizer.rb

Defined Under Namespace

Modules: LanguageSupport, Stemmer Classes: Bm25, CompoundTokenizer, DowncaseFilter, Idf, InvertedIndex, NgramTokenizer, Pipeline, RemovePunctuationFilter, StandardWhitespaceTokenizer, StemmerFilter, StopWordsFilter, StripFilter, SynonymsFilter, Tf

Constant Summary collapse

LANGUAGE_SUPPORTS =
{
  pt: MiniSearch::LanguageSupport::Portuguese
}
VERSION =
"1.2.0"

Class Method Summary collapse

Class Method Details

.from_config_file(file) ⇒ Object



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
# File 'lib/mini_search.rb', line 81

def self.from_config_file(file)
  raise "file not found '#{file}'" unless File.exists?(file)

  cores = YAML.load_file(file)['cores']

  cores.map do |core|
    lang = core['lang'].to_sym

    new_localized_index(
      lang,
      stop_words: core['stop_words'],
      synonyms_map: core['synonyms_map'].transform_values { |v| v.split(',') }
    )
  end
end

.new(indexing_pipeline, querying_pipeline) ⇒ Object



25
26
27
# File 'lib/mini_search.rb', line 25

def self.new(indexing_pipeline, querying_pipeline)
  MiniSearch::InvertedIndex.new(indexing_pipeline, querying_pipeline)
end

.new_index(stop_words: [], synonyms_map: {}, stemmer: nil, ngrams: nil) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
# File 'lib/mini_search.rb', line 29

def self.new_index(stop_words: [], synonyms_map: {}, stemmer: nil, ngrams: nil)
  tokenizer =
    if ngrams
      NgramTokenizer.new(ngrams)
    else
      StandardWhitespaceTokenizer.new
    end

  strip_filter = StripFilter.new
  remove_punctuation_filter = RemovePunctuationFilter.new
  downcase_filter = DowncaseFilter.new
  stop_words_filter = StopWordsFilter.new(stop_words)
  stemmer_filter = StemmerFilter.new(stemmer)
  synonyms_filter = SynonymsFilter.new(synonyms_map)

  indexing_pipeline = Pipeline.new(
    tokenizer,
    [
      strip_filter,
      remove_punctuation_filter,
      downcase_filter,
      stop_words_filter,
      stemmer_filter
    ]
  )

  querying_pipeline = Pipeline.new(
    tokenizer,
    [
      strip_filter,
      remove_punctuation_filter,
      downcase_filter,
      stop_words_filter,
      stemmer_filter,
      synonyms_filter
    ]
  )

  new(indexing_pipeline, querying_pipeline)
end

.new_localized_index(lang, synonyms_map: {}, stop_words: [], ngrams: nil) ⇒ Object



70
71
72
73
74
75
76
77
78
79
# File 'lib/mini_search.rb', line 70

def self.new_localized_index(lang, synonyms_map: {}, stop_words: [], ngrams: nil)
  language_support = find_language_support(lang, stop_words)

  new_index(
    stop_words: language_support.stop_words,
    stemmer: language_support.stemmer,
    synonyms_map: synonyms_map,
    ngrams: ngrams
  )
end