Skip to content

Commit

Permalink
Merge pull request #24 from kids-first/create-search-fields
Browse files Browse the repository at this point in the history
✨ Add searchText field
  • Loading branch information
evans-g-crsj authored Apr 11, 2023
2 parents 04d5498 + 139729d commit bffdb71
Show file tree
Hide file tree
Showing 6 changed files with 59 additions and 8 deletions.
6 changes: 5 additions & 1 deletion .dockerignore
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@ __pycache__
.gitignore
README.md
run.sh
Jenkinsfile
Jenkinsfile
.mypy_cache/
.dmypy.json
dmypy.json
.vscode
4 changes: 2 additions & 2 deletions scripts/console
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
#!/bin/bash

# scripts/console: Open a container instance of the applicaiton for testing/debugging
# scripts/console: Open a container instance of the application for testing/debugging

# Once in a terminal you can run, for instance: "black <my_python_file>" to reformat a file
docker run --rm -it -v "$PWD":/code --workdir /code python:3.9-slim-buster sh -c "pip install -r src/requirements.txt -r requirements.txt && sh"
docker run --rm -it -v "$PWD":/code --network=host --workdir /code python:3.9-slim-buster sh -c "pip install -r src/requirements.txt -r requirements.txt && sh"
13 changes: 13 additions & 0 deletions scripts/localsuperlinter
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
#!/bin/bash

# At the root of the project you can run this command to simulate super linter (you may want to tweak the env vars).
docker run --rm \
-e RUN_LOCAL=true \
-e USE_FIND_ALGORITHM=true \
-e VALIDATE_PYTHON=true \
-e VALIDATE_PYTHON_BLACK=true \
-e VALIDATE_PYTHON_FLAKE=true \
-e IGNORE_GENERATED_FILES=true \
-v /"${PWD}":/tmp/lint \
-w /tmp/lint \
github/super-linter
24 changes: 22 additions & 2 deletions src/copy_member_to_members.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,29 @@ def main():
es_client.ingest.put_pipeline(
PIPELINE_ID,
{
"description": "Removes the 'virtualStudies' field",
"description": "Copy all members",
"processors": [
{"remove": {"field": "virtualStudies", "ignore_missing": True}}
{
"remove": {
"description": "Removes the 'virtualStudies' field",
"field": "virtualStudies",
"ignore_missing": True,
}
},
{
"script": {
"lang": "painless",
"source": """
def searchText = [];
for (def x : [ctx['firstName'], ctx['lastName'], ctx['institution']]) {
if (x != null && !x.trim().isEmpty() && !searchText.contains(x.toLowerCase())) {
searchText.add(x.toLowerCase())
}
ctx['searchText'] = searchText
}
""",
}
},
],
},
)
Expand Down
8 changes: 8 additions & 0 deletions src/mappings.py
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,13 @@
},
"member_ascii_folding": {"type": "asciifolding", "preserve_original": True},
},
"normalizer": {
"custom_normalizer": {
"type": "custom",
"char_filter": [],
"filter": "lowercase",
}
},
}
}

Expand Down Expand Up @@ -177,6 +184,7 @@
"analyzer": "autocomplete",
"fields": {"raw": {"type": "keyword"}},
},
"searchText": {"type": "keyword", "normalizer": "custom_normalizer"},
}
},
}
Expand Down
12 changes: 9 additions & 3 deletions src/transform.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,14 +12,17 @@ def transform_event_to_docs(event, index, omit):
a generator with docs"""
for record in event["Records"]:
payload = loads(record["body"])
first_name = payload.get("firstName")
last_name = payload.get("lastName")
institution = payload.get("institution")
yield dict(
filter(
lambda x: x[0] not in omit if len(omit) > 0 else True,
{
"_index": index,
"_id": payload["_id"],
"firstName": payload.get("firstName"),
"lastName": payload.get("lastName"),
"firstName": first_name,
"lastName": last_name,
"email": payload.get("email"),
"hashedEmail": payload.get("hashedEmail"),
"institutionalEmail": payload.get("institutionalEmail"),
Expand All @@ -29,7 +32,7 @@ def transform_event_to_docs(event, index, omit):
"roles": payload.get("roles"),
"title": payload.get("title"),
"jobTitle": payload.get("jobTitle"),
"institution": payload.get("institution"),
"institution": institution,
"city": payload.get("city"),
"state": payload.get("state"),
"country": payload.get("country"),
Expand All @@ -43,6 +46,9 @@ def transform_event_to_docs(event, index, omit):
],
"linkedin": payload.get("linkedin", ""),
"website": payload.get("website", ""),
"searchText": list(
set(filter(None, [first_name, last_name, institution]))
),
}.items(),
)
)

0 comments on commit bffdb71

Please sign in to comment.