Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

change simple concept search to score based on aggregate relevance #372

Merged
merged 4 commits into from
Oct 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading