Skip to content

Commit

Permalink
Merge pull request #372 from helxplatform/fix/simple-search-explain
Browse files Browse the repository at this point in the history
change simple concept search to score based on aggregate relevance
  • Loading branch information
YaphetKG authored Oct 17, 2024
2 parents 0de6dfa + 7b94999 commit ea2d757
Show file tree
Hide file tree
Showing 4 changed files with 34 additions and 7 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/trivy-pr-scan.yml
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ jobs:
# We still fail the job if results are found, so below will always run
# unless manually canceled.
- name: Upload Trivy scan results to GitHub Security tab
uses: github/codeql-action/upload-sarif@v2
uses: github/codeql-action/upload-sarif@v3
if: '!cancelled()'
with:
sarif_file: 'trivy-results.sarif'
1 change: 1 addition & 0 deletions requirements.txt
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@ MarkupSafe
ormar
mistune
pluggy
pydantic==2.9.2
pyrsistent
pytest
pytest-asyncio
Expand Down
36 changes: 31 additions & 5 deletions src/dug/core/async_search.py
Original file line number Diff line number Diff line change
Expand Up @@ -728,13 +728,39 @@ def _get_var_query(self, concept, fuzziness, prefix_length, query):
def get_simple_search_query(self, query):
"""Returns ES query that allows to use basic operators like AND, OR, NOT...
More info here https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-simple-query-string-query.html."""
simple_query_string_search = {
"query": query,
"default_operator": "and",
"flags": "OR|AND|NOT|PHRASE|PREFIX"
}
search_query = {
"query": {
"simple_query_string": {
"query": query,
"fields": ["name", "description", "search_terms"],
"default_operator": "and",
"flags": "OR|AND|NOT|PHRASE|PREFIX"
"function_score": {
"query": {
"bool": {
"should": [
{
"simple_query_string": {
**simple_query_string_search,
"fields": ["name"]
}
},
{
"simple_query_string": {
**simple_query_string_search,
"fields": ["description"]
}
},
{
"simple_query_string": {
**simple_query_string_search,
"fields": ["search_terms"]
}
}
]
}
},
"score_mode": "sum"
}
}
}
Expand Down
2 changes: 1 addition & 1 deletion src/dug/server.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@

APP = FastAPI(
title="Dug Search API",
root_path=os.environ.get("ROOT_PATH", "/"),
root_path=os.environ.get("ROOT_PATH", ""),
)

APP.add_middleware(
Expand Down

0 comments on commit ea2d757

Please sign in to comment.