From 5c7383c6d1fc1189268e408bc17ff587612ce2a0 Mon Sep 17 00:00:00 2001 From: "Daniel J. Summers" Date: Sun, 29 Jan 2023 20:21:59 -0500 Subject: [PATCH] Refine private search (#39) --- src/JobsJobsJobs/Profiles/Data.fs | 24 +++++++++++++++--------- src/JobsJobsJobs/Profiles/Domain.fs | 9 +++------ src/JobsJobsJobs/Profiles/Handlers.fs | 2 +- src/JobsJobsJobs/Profiles/Views.fs | 21 ++++++++++----------- 4 files changed, 29 insertions(+), 27 deletions(-) diff --git a/src/JobsJobsJobs/Profiles/Data.fs b/src/JobsJobsJobs/Profiles/Data.fs index 4f28308..1ad9fd6 100644 --- a/src/JobsJobsJobs/Profiles/Data.fs +++ b/src/JobsJobsJobs/Profiles/Data.fs @@ -60,14 +60,19 @@ let search (search : ProfileSearchForm) = backgroundTask { "p.data ->> 'continentId' = @continentId", [ "@continentId", Sql.string search.ContinentId ] if search.RemoteWork <> "" then "p.data ->> 'isRemote' = @remote", [ "@remote", jsonBool (search.RemoteWork = "yes") ] - if search.Skill <> "" then - "EXISTS ( - SELECT 1 FROM jsonb_array_elements(p.data['skills']) x(elt) - WHERE x ->> 'description' ILIKE @description)", - [ "@description", like search.Skill ] - if search.BioExperience <> "" then - "(p.data ->> 'biography' ILIKE @text OR p.data ->> 'experience' ILIKE @text)", - [ "@text", like search.BioExperience ] + if search.Text <> "" then + " p.data ->> 'region' ILIKE @text + OR p.data ->> 'biography' ILIKE @text + OR p.data ->> 'experience' ILIKE @text + OR EXISTS ( + SELECT 1 FROM jsonb_array_elements(p.data['skills']) x(elt) + WHERE x ->> 'description' ILIKE @text) + OR EXISTS ( + SELECT 1 FROM jsonb_array_elements(p.data['history']) x(elt) + WHERE x ->> 'employer' ILIKE @text + OR x ->> 'position' ILIKE @text + OR x ->> 'description' ILIKE @text)", + [ "@text", like search.Text ] ] let! results = dataSource () @@ -75,7 +80,8 @@ let search (search : ProfileSearchForm) = backgroundTask { SELECT p.*, c.data AS cit_data FROM {Table.Profile} p INNER JOIN {Table.Citizen} c ON c.id = p.id - WHERE p.data ->> 'isLegacy' = 'false' + WHERE p.data ->> 'isLegacy' = 'false' + AND p.data ->> 'visibility' <> '{ProfileVisibility.toString Hidden}' {searchSql searches}" |> Sql.parameters (searches |> List.collect snd) |> Sql.executeAsync (fun row -> diff --git a/src/JobsJobsJobs/Profiles/Domain.fs b/src/JobsJobsJobs/Profiles/Domain.fs index 3c352d4..5c8ff4a 100644 --- a/src/JobsJobsJobs/Profiles/Domain.fs +++ b/src/JobsJobsJobs/Profiles/Domain.fs @@ -107,14 +107,11 @@ type ProfileSearchForm = { /// Retrieve citizens from this continent ContinentId : string - /// Text for a search within a citizen's skills - Skill : string - - /// Text for a search with a citizen's professional biography and experience fields - BioExperience : string - /// Whether to retrieve citizens who do or do not want remote work RemoteWork : string + + /// Text for a search within a citizen's region, professional bio, skills, experience, and employment history + Text : string } diff --git a/src/JobsJobsJobs/Profiles/Handlers.fs b/src/JobsJobsJobs/Profiles/Handlers.fs index d60f14c..10f69ba 100644 --- a/src/JobsJobsJobs/Profiles/Handlers.fs +++ b/src/JobsJobsJobs/Profiles/Handlers.fs @@ -76,7 +76,7 @@ let search : HttpHandler = requireUser >=> fun next ctx -> task { let form = match ctx.TryBindQueryString () with | Ok f -> f - | Error _ -> { ContinentId = ""; RemoteWork = ""; Skill = ""; BioExperience = "" } + | Error _ -> { ContinentId = ""; RemoteWork = ""; Text = "" } let! results = task { if string ctx.Request.Query["searched"] = "true" then let! it = Data.search form diff --git a/src/JobsJobsJobs/Profiles/Views.fs b/src/JobsJobsJobs/Profiles/Views.fs index 03ea4c8..f39f980 100644 --- a/src/JobsJobsJobs/Profiles/Views.fs +++ b/src/JobsJobsJobs/Profiles/Views.fs @@ -438,8 +438,7 @@ let publicSearch (m : PublicSearchForm) continents (results : PublicSearchResult /// Logged-on search page let search (m : ProfileSearchForm) continents tz (results : ProfileSearchResult list option) = - pageWithTitle "Search Profiles" [ - if Option.isNone results then + [ if Option.isNone results then p [] [ txt "Enter one or more criteria to filter results, or just click “Search” to list all " txt "profiles." @@ -448,10 +447,10 @@ let search (m : ProfileSearchForm) continents tz (results : ProfileSearchResult form [ _class "container"; _method "GET"; _action "/profile/search" ] [ input [ _type "hidden"; _name "searched"; _value "true" ] div [ _class "row" ] [ - div [ _class "col-12 col-sm-6 col-md-4 col-lg-3" ] [ + div [ _class "col-12 col-sm-6 col-md-4 col-lg-3 mb-3" ] [ continentList [] "ContinentId" continents (Some "Any") m.ContinentId false ] - div [ _class "col-12 col-sm-6 col-offset-md-2 col-lg-3 col-offset-lg-0" ] [ + div [ _class "col-12 col-sm-6 col-offset-md-2 col-lg-3 col-offset-lg-0 mb-3" ] [ label [ _class "jjj-label" ] [ txt "Seeking Remote Work?" ]; br [] div [ _class "form-check form-check-inline" ] [ input [ _type "radio"; _id "remoteNull"; _name (nameof m.RemoteWork); _value "" @@ -469,13 +468,11 @@ let search (m : ProfileSearchForm) continents tz (results : ProfileSearchResult label [ _class "form-check-label"; _for "remoteNo" ] [ txt "No" ] ] ] - div [ _class "col-12 col-sm-6 col-lg-3" ] [ - textBox [ _maxlength "1000" ] (nameof m.Skill) m.Skill "Skill" false - div [ _class "form-text" ] [ txt "(free-form text)" ] - ] - div [ _class "col-12 col-sm-6 col-lg-3" ] [ - textBox [ _maxlength "1000" ] (nameof m.BioExperience) m.BioExperience "Bio / Experience" false - div [ _class "form-text" ] [ txt "(free-form text)" ] + div [ _class "col-12 col-sm-12 col-lg-6 mb-3" ] [ + textBox [ _maxlength "1000" ] (nameof m.Text) m.Text "Text Search" false + div [ _class "form-text" ] [ + txt "searches Region, Professional Biography, Skills, Employment History, and Experience" + ] ] ] div [ _class "row" ] [ @@ -515,6 +512,8 @@ let search (m : ProfileSearchForm) continents tz (results : ProfileSearchResult ] | None -> () ] + |> pageWithTitle "Search Profiles" + /// Display a profile let private displayProfile (it : ProfileForView) isPublic isPrint =