Chars: Reduce overtriggering (#4033)
* FIX FOR ISSUE #4028 -> Set triggers to only apply to start of search string so the IA isn't triggered for programming-related searches -> Removed triggers 'characters count', 'length of string' and 'chars' as they are unintuitive and can clash with programming requests -> Added 'of' as a leading word to be removed so queries such as 'length in chars of foo' count only the characters in 'foo' -> Updated test script to reflect these changes * Fix #4028 - reduce overtriggering of 'Chars' goodie -> Set triggers to only apply to start of search string so the IA isn't triggered for programming-related searches -> Removed triggers 'characters count', 'length of string' and 'chars' as they are unintuitive and can clash with programming requests -> Added 'of' as a leading word to be removed so queries such as 'length in chars of foo' count only the characters in 'foo' -> Updated test script to reflect these changesmaster
parent
5ff250cab1
commit
f02048c71f
|
@ -5,16 +5,13 @@ use strict;
|
|||
use DDG::Goodie;
|
||||
use Text::Trim;
|
||||
|
||||
triggers startend =>
|
||||
'chars',
|
||||
triggers start =>
|
||||
'number of characters',
|
||||
'number of chars',
|
||||
'num chars',
|
||||
'num characters',
|
||||
'char count',
|
||||
'character count',
|
||||
'characters count',
|
||||
'length of string',
|
||||
'length in characters',
|
||||
'length in chars';
|
||||
|
||||
|
@ -25,10 +22,10 @@ handle remainder => sub {
|
|||
my ($str) = @_;
|
||||
return if !$str;
|
||||
|
||||
# remove leading word 'in',
|
||||
# e.g. 'chars in mississippi' would just count the string 'mississippi'.
|
||||
$str =~ s/^\s*in\b//;
|
||||
|
||||
# remove leading words 'in' and 'of,
|
||||
# e.g. 'number of characters in mississippi' would just count the string 'mississippi'.
|
||||
$str =~ s/^\s*(in|of)\b//;
|
||||
|
||||
# trim spaces at beg and end of string
|
||||
$str = trim $str;
|
||||
|
||||
|
|
71
t/Chars.t
71
t/Chars.t
|
@ -34,65 +34,86 @@ ddg_goodie_test(
|
|||
[qw( DDG::Goodie::Chars)],
|
||||
|
||||
# string can be inside double quotes, and quotes shouldn't be counted as characters
|
||||
'chars in "my string"' => build_test(9, 'my string'),
|
||||
'num chars in "my string"' => build_test(9, 'my string'),
|
||||
|
||||
# string can be inside single quotes, and single quotes shouldn't be counted as characters
|
||||
"chars in 'my string'" => build_test(9, 'my string'),
|
||||
"num chars in 'my string'" => build_test(9, 'my string'),
|
||||
|
||||
# string shouldn't need quotes
|
||||
'chars in my string' => build_test(9, 'my string'),
|
||||
'num chars in my string' => build_test(9, 'my string'),
|
||||
|
||||
# extra spaces shouldn't be counted
|
||||
'chars in my string ' => build_test(9, 'my string'),
|
||||
'num chars in my string ' => build_test(9, 'my string'),
|
||||
|
||||
# extra spaces before 'in' should still trigger
|
||||
'chars in my string' => build_test(9, 'my string'),
|
||||
'num chars in my string' => build_test(9, 'my string'),
|
||||
|
||||
# one character strings should say '1 character long' instead of '1 characters long'
|
||||
'chars in "1"' => build_test(1, '1'),
|
||||
'num chars in "1"' => build_test(1, '1'),
|
||||
|
||||
# trigger plus empty quotes should return a length of 0.
|
||||
'chars in ""' => build_test(0, ''),
|
||||
'num chars in ""' => build_test(0, ''),
|
||||
|
||||
#above triggers should work the same way with the word 'of'
|
||||
# string can be inside double quotes, and quotes shouldn't be counted as characters
|
||||
'num chars of "my string"' => build_test(9, 'my string'),
|
||||
|
||||
# string can be inside single quotes, and single quotes shouldn't be counted as characters
|
||||
"num chars of 'my string'" => build_test(9, 'my string'),
|
||||
|
||||
# string shouldn't need quotes
|
||||
'num chars of my string' => build_test(9, 'my string'),
|
||||
|
||||
# extra spaces shouldn't be counted
|
||||
'num chars of my string ' => build_test(9, 'my string'),
|
||||
|
||||
# extra spaces before 'in' should still trigger
|
||||
'num chars of my string' => build_test(9, 'my string'),
|
||||
|
||||
# one character strings should say '1 character long' instead of '1 characters long'
|
||||
'num chars of "1"' => build_test(1, '1'),
|
||||
|
||||
# trigger plus empty quotes should return a length of 0.
|
||||
'num chars of ""' => build_test(0, ''),
|
||||
|
||||
|
||||
|
||||
#####
|
||||
# triggers that SHOULD load the IA
|
||||
|
||||
'chars "my string"' => build_test(9, 'my string'),
|
||||
'chars in "my string"' => build_test(9, 'my string'),
|
||||
'number of chars in "my string"' => build_test(9, 'my string'),
|
||||
'"my string" number of chars' => build_test(9, 'my string'),
|
||||
'number of characters in "my string"' => build_test(9, 'my string'),
|
||||
'"my string" number of characters' => build_test(9, 'my string'),
|
||||
'num chars "my string"' => build_test(9, 'my string'),
|
||||
'"my string" num chars' => build_test(9, 'my string'),
|
||||
'num chars in "my string"' => build_test(9, 'my string'),
|
||||
'num characters "my string"' => build_test(9, 'my string'),
|
||||
'"my string" num characters' => build_test(9, 'my string'),
|
||||
'num characters in "my string"' => build_test(9, 'my string'),
|
||||
'char count "my string"' => build_test(9, 'my string'),
|
||||
'"my string" char count' => build_test(9, 'my string'),
|
||||
'char count in "my string"' => build_test(9, 'my string'),
|
||||
'character count "my string"' => build_test(9, 'my string'),
|
||||
'"my string" character count' => build_test(9, 'my string'),
|
||||
'character count in "my string"' => build_test(9, 'my string'),
|
||||
'length of string "my string"' => build_test(9, 'my string'),
|
||||
'"my string" length of string' => build_test(9, 'my string'),
|
||||
'length in characters "my string"' => build_test(9, 'my string'),
|
||||
'"my string" length in characters' => build_test(9, 'my string'),
|
||||
'length in chars "my string"' => build_test(9, 'my string'),
|
||||
'"my string" length in chars' => build_test(9, 'my string'),
|
||||
|
||||
#####
|
||||
'count characters in my string' => build_test(9, 'my string'),
|
||||
|
||||
# triggers that SHOULD NOT load the IA
|
||||
'length of string "my string"' => undef,
|
||||
|
||||
# a trigger query with no text should not trigger the IA
|
||||
'chars' => undef,
|
||||
'num chars' => undef,
|
||||
|
||||
# a trigger query plus the word 'in' should not trigger the IA
|
||||
'chars in' => undef,
|
||||
'num chars in' => undef,
|
||||
|
||||
# a trigger query plus the word 'in' and spaces should not trigger the IA
|
||||
'chars in ' => undef,
|
||||
'num chars in ' => undef,
|
||||
|
||||
#above triggers with 'of' should also not not trigger the IA
|
||||
|
||||
# a trigger query plus the word 'of' should not trigger the IA
|
||||
'num chars of' => undef,
|
||||
|
||||
# a trigger query plus the word 'of' and spaces should not trigger the IA
|
||||
'num chars of ' => undef,
|
||||
|
||||
|
||||
# searches for TV characters should not load the IA
|
||||
'Sopranos characters' => undef,
|
||||
|
|
Loading…
Reference in New Issue