rails-contact 0.1.19 → 0.1.20
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +10 -0
- data/lib/rails/contact/search/backends/database.rb +5 -1
- data/lib/rails/contact/version.rb +1 -1
- data/spec/search/database_backend_spec.rb +8 -0
- metadata +1 -1
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 7db41d62f84bab3daa7116637e110537293232619c6568f0b55bc4d3aba89419
|
|
4
|
+
data.tar.gz: 05cf0def4af33f2be02b0ea14cd6a41a151bc115d8a7f5908e08b67ade7273cd
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 51a23f400c382b01beaf54bb862e53cbd6b3a353379adb2752ddb520dfcb1e8323bdb4b40462bbbf5c22cefa97cce5d0a909bf600897433b2f2cb28df02179df
|
|
7
|
+
data.tar.gz: 51012c9824d63061668b251c5bf6df60999b182e32107a164e2f5f309a7bb50891ac7690fb039489ac95abc926eb16dc864056920bb50cad823eefaca051a55c
|
data/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,15 @@
|
|
|
1
1
|
# Changelog
|
|
2
2
|
|
|
3
|
+
## 0.1.20
|
|
4
|
+
|
|
5
|
+
- **A phone typed without its country code is found again.** Since search
|
|
6
|
+
became prefix-only, "9812345670" no longer matched "+919812345670": the
|
|
7
|
+
stored number starts with the country code, so no prefix of the typed
|
|
8
|
+
digits can reach it. A query of seven or more digits and nothing else now
|
|
9
|
+
matches anywhere in the stored number. Only that case scans the phones
|
|
10
|
+
table; names, emails, labels and shorter digit runs stay index-served
|
|
11
|
+
prefix matches.
|
|
12
|
+
|
|
3
13
|
## 0.1.19
|
|
4
14
|
|
|
5
15
|
- **Result counts are exact again, and bounded.** 0.1.17 replaced large exact
|
|
@@ -50,6 +50,10 @@ module Rails
|
|
|
50
50
|
# still matches.
|
|
51
51
|
def apply_query(scoped, query)
|
|
52
52
|
prefix = "#{query.downcase}%"
|
|
53
|
+
# A long run of digits is a phone typed without its country code
|
|
54
|
+
# ("9812345670" for "+919812345670"), which no prefix can find. Only
|
|
55
|
+
# that case scans the phones table; every other arm stays a prefix.
|
|
56
|
+
phone = query.match?(/\A\d{7,}\z/) ? "%#{query}%" : "#{query}%"
|
|
53
57
|
scoped.where(
|
|
54
58
|
"rails_contact_contacts.id IN (" \
|
|
55
59
|
"SELECT c.id FROM rails_contact_contacts c WHERE LOWER(c.given_name) LIKE :q " \
|
|
@@ -62,7 +66,7 @@ module Rails
|
|
|
62
66
|
"JOIN rails_contact_labels l ON l.id = cl.label_id WHERE LOWER(l.name) LIKE :q" \
|
|
63
67
|
")",
|
|
64
68
|
q: prefix,
|
|
65
|
-
raw:
|
|
69
|
+
raw: phone,
|
|
66
70
|
plus_raw: "+#{query}%"
|
|
67
71
|
)
|
|
68
72
|
end
|
|
@@ -104,6 +104,14 @@ RSpec.describe Rails::Contact::Search::Backends::Database do
|
|
|
104
104
|
expect(search_for("91981")).to include(dave)
|
|
105
105
|
end
|
|
106
106
|
|
|
107
|
+
it "matches a phone typed without its country code" do
|
|
108
|
+
expect(search_for("9812345670")).to include(dave)
|
|
109
|
+
end
|
|
110
|
+
|
|
111
|
+
it "keeps short digit runs a prefix match" do
|
|
112
|
+
expect(search_for("98123")).not_to include(dave)
|
|
113
|
+
end
|
|
114
|
+
|
|
107
115
|
it "matches the full plus-form phone prefix" do
|
|
108
116
|
expect(search_for("+91981")).to include(dave)
|
|
109
117
|
end
|