Skip to content
This repository was archived by the owner on Jan 27, 2023. It is now read-only.

Commit a999eda

Browse files
committed
raise error if tokenLength is provided and return message stating it has been deprecated
1 parent 99bc07e commit a999eda

2 files changed

Lines changed: 16 additions & 0 deletions

File tree

lib/cipherstash/analysis/text_processor.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -46,6 +46,10 @@ def build_token_filters(array)
4646
TokenFilters::Downcase.new(obj)
4747

4848
when "ngram"
49+
if obj["tokenLength"]
50+
raise CipherStash::Client::Error::InternalError, "'tokenLength' is deprecated. Use 'minLength' and 'maxLength' for the ngram filter."
51+
end
52+
4953
unless obj["minLength"].instance_of?(Integer) && obj["maxLength"].instance_of?(Integer)
5054
raise CipherStash::Client::Error::InternalError, "The values provided to the min and max length must be of type Integer."
5155
end

spec/cipherstash/analysis/text_processor_spec.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,18 @@
4444
}.to raise_error(CipherStash::Client::Error::InternalError, "The ngram filter min length must be less than or equal to the max length")
4545
end
4646

47+
it "raises an error if tokenLength is provided" do
48+
expect {
49+
CipherStash::Analysis::TextProcessor.new({
50+
"tokenFilters" => [
51+
{ "kind" => "downcase" },
52+
{ "kind" => "ngram", "tokenLength" => 3 }
53+
],
54+
"tokenizer" => { "kind" => "standard" }
55+
})
56+
}.to raise_error(CipherStash::Client::Error::InternalError, "'tokenLength' is deprecated. Use 'minLength' and 'maxLength' for the ngram filter.")
57+
end
58+
4759
it "splits text into ngrams using min length of 3 and max length of 8" do
4860
tokenizer =
4961
CipherStash::Analysis::TextProcessor.new({

0 commit comments

Comments
 (0)