Skip to content

Commit 9ae2036

Browse files
authored
Merge pull request #123 from fpdcc/patch/search-rankings
Improve search scores for direct matches
2 parents afa344e + b4c94f2 commit 9ae2036

File tree

4 files changed

+29
-9
lines changed

4 files changed

+29
-9
lines changed

.github/workflows/main.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ jobs:
1919
run: |
2020
mkdir -p data && touch data/requirements.txt
2121
cp .env.example .env
22-
docker-compose -f docker-compose.yml -f tests/docker-compose.yml run --rm app
22+
docker compose -f docker-compose.yml -f tests/docker-compose.yml run --rm app
2323
deploy:
2424
if:
2525
contains('

README.md

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -27,13 +27,13 @@ cp docsearch/local_settings.example.py docsearch/local_settings.dev.py
2727
Next, build containers:
2828

2929
```
30-
docker-compose build
30+
docker compose build
3131
```
3232

3333
Run the app:
3434

3535
```
36-
docker-compose up
36+
docker compose up
3737
```
3838

3939
The app will be available at http://localhost:8000. The database will be exposed
@@ -42,7 +42,7 @@ on port 32001.
4242
Create a superuser to view the application:
4343

4444
```
45-
docker-compose run --rm app ./manage.py createsuperuser
45+
docker compose run --rm app ./manage.py createsuperuser
4646
```
4747

4848
### Loading initial data
@@ -67,27 +67,27 @@ cp -R ./document-search-data/ ./document-search/data/
6767
Then, load initial data using GNU Make:
6868

6969
```
70-
docker-compose -f docker-compose.yml -f data/docker-compose.yml run --rm app make all
70+
docker compose -f docker-compose.yml -f data/docker-compose.yml run --rm app make all
7171
```
7272

7373
To create the search index, start by bringing up Solr in one shell:
7474

7575
```
76-
docker-compose up solr
76+
docker compose up solr
7777
```
7878

7979
Then, in another shell, run the `rebuild_index` command:
8080

8181
```
82-
docker-compose run --rm app ./manage.py rebuild_index
82+
docker compose run --rm app ./manage.py rebuild_index
8383
```
8484

8585
### Running tests
8686

8787
Run tests with Docker Compose:
8888

8989
```
90-
docker-compose -f docker-compose.yml -f tests/docker-compose.yml run --rm app
90+
docker compose -f docker-compose.yml -f tests/docker-compose.yml run --rm app
9191
```
9292

9393
## Deployment

docsearch/views/base.py

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -146,6 +146,26 @@ def form_valid(self, form):
146146

147147
def get_queryset(self):
148148
sqs = super().get_queryset().models(self.model)
149+
150+
q = self.request.GET.get('q')
151+
if q:
152+
"""
153+
Boost results that contain direct matches of each term in the query,
154+
regardless of whether any terms are enclosed in double quotes.
155+
Terms in double quotes are exact match terms, so give them a bit of
156+
an extra boost, and boost them as is - whitespace and all.
157+
"""
158+
exact_match_re = re.compile(r'"(?P<phrase>.*?)"')
159+
tokens = exact_match_re.split(q)
160+
exacts = exact_match_re.findall(q)
161+
162+
for t in tokens:
163+
if t and not t.strip().startswith("-"):
164+
if t in exacts:
165+
sqs = sqs.boost(t, 1)
166+
else:
167+
sqs = sqs.boost(t, .5)
168+
149169
for facet_field in self.facet_fields:
150170
# Sort facet options alphabetically, not by hit count
151171
sqs = sqs.facet(facet_field, sort='index', limit=1000)

scripts/after_install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ $VENV_DIR/bin/python $PROJECT_DIR/scripts/render_configs.py $DEPLOYMENT_ID $DEPL
7878
echo "DEPLOYMENT_ID='$DEPLOYMENT_ID'" > $PROJECT_DIR/docsearch/deployment.py
7979

8080
# Make sure Solr is running
81-
(docker ps | grep document-search-solr) || (cd $PROJECT_DIR && docker-compose up -d solr)
81+
(docker ps | grep document-search-solr) || (cd $PROJECT_DIR && docker compose up -d solr)
8282

8383

8484
# Add the virtualenv directory name to python command in the script

0 commit comments

Comments
 (0)