Skip to content

Commit

Permalink
feat: add index for levenshtein similarity
Browse files Browse the repository at this point in the history
  • Loading branch information
ghivert committed Aug 1, 2024
1 parent 194341f commit 7f89297
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
-- migrate:up
create index package_name_index on package_type_fun_signature (name, kind);

-- migrate:down
drop index package_name_index;
10 changes: 9 additions & 1 deletion apps/backend/db/schema.sql
Original file line number Diff line number Diff line change
Expand Up @@ -438,6 +438,13 @@ ALTER TABLE ONLY public.search_analytics
ADD CONSTRAINT search_analytics_pkey PRIMARY KEY (query);


--
-- Name: package_name_index; Type: INDEX; Schema: public; Owner: -
--

CREATE INDEX package_name_index ON public.package_type_fun_signature USING btree (name, kind);


--
-- Name: package_type_fun_signature_documentation; Type: INDEX; Schema: public; Owner: -
--
Expand Down Expand Up @@ -582,4 +589,5 @@ INSERT INTO public.schema_migrations (version) VALUES
('20240521174525'),
('20240521204341'),
('20240801164720'),
('20240801211520');
('20240801211520'),
('20240801220817');
4 changes: 2 additions & 2 deletions apps/backend/src/backend/postgres/queries.gleam
Original file line number Diff line number Diff line change
Expand Up @@ -439,8 +439,8 @@ pub fn upsert_package_type_fun_signature(
pub fn find_similar_type_names(db: pgo.Connection, name: String) {
"SELECT DISTINCT ON (name) name
FROM package_type_fun_signature
WHERE kind = 'type_definition'
AND levenshtein_less_equal(name, $1, 2) <= 2;"
WHERE (kind = 'type_definition' OR kind = 'type_alias')
AND levenshtein_less_equal(name, $1, 2) <= 2"
|> pgo.execute(db, [pgo.text(name)], dynamic.element(0, dynamic.string))
|> result.map_error(error.DatabaseError)
|> result.map(fn(r) { r.rows })
Expand Down

0 comments on commit 7f89297

Please sign in to comment.