Skip to content

Commit

Permalink
Merge pull request #121 from opencivicdata/bill-search
Browse files Browse the repository at this point in the history
add SearchableBill model - experimental full-text-search support
  • Loading branch information
jamesturk authored Jul 9, 2019
2 parents 4e54f34 + a8946b6 commit ff7e3b5
Show file tree
Hide file tree
Showing 6 changed files with 73 additions and 5 deletions.
3 changes: 0 additions & 3 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,6 @@ python:
- "3.7"
env:
- DJANGO_VERSION=1.11
- DJANGO_VERSION=2.0
- DJANGO_VERSION=2.1
- DJANGO_VERSION=2.2
install:
Expand All @@ -29,8 +28,6 @@ after_success:
- coveralls
matrix:
exclude:
- python: "2.7"
env: DJANGO_VERSION=2.0
- python: "2.7"
env: DJANGO_VERSION=2.1
- python: "2.7"
Expand Down
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Changelog

## 2.4.0

Improvements requiring migrations:

* added experimental SearchableBill model

## 2.3.0 (2018-12-04)

Improvements requiring migrations:
Expand Down
31 changes: 31 additions & 0 deletions opencivicdata/legislative/migrations/0009_searchablebill.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# Generated by Django 2.0.13 on 2019-06-27 14:32

import django.contrib.postgres.search
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('legislative', '0008_longer_event_name'),
]

operations = [
migrations.CreateModel(
name='SearchableBill',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('search_vector', django.contrib.postgres.search.SearchVectorField(default=None)),
('all_titles', models.TextField(default='')),
('raw_text', models.TextField(default='')),
('is_error', models.BooleanField(default=False)),
('created_at', models.DateTimeField(auto_now_add=True)),
('bill', models.OneToOneField(null=True, on_delete=django.db.models.deletion.CASCADE, related_name='searchable', to='legislative.Bill')),
('version_link', models.OneToOneField(on_delete=django.db.models.deletion.CASCADE, related_name='searchable', to='legislative.BillVersionLink')),
],
options={
'db_table': 'opencivicdata_searchablebill',
},
),
]
2 changes: 1 addition & 1 deletion opencivicdata/legislative/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from .session import LegislativeSession
from .bill import (Bill, BillAbstract, BillTitle, BillIdentifier, RelatedBill, BillSponsorship,
BillDocument, BillVersion, BillDocumentLink, BillVersionLink, BillSource,
BillActionRelatedEntity, BillAction)
BillActionRelatedEntity, BillAction, SearchableBill)
from .vote import (VoteEvent, VoteCount, PersonVote, VoteSource)
from .event import (Event, EventLocation, EventMedia, EventMediaLink, EventDocument, EventLink,
EventSource, EventParticipant, EventAgendaItem, EventRelatedEntity,
Expand Down
34 changes: 34 additions & 0 deletions opencivicdata/legislative/models/bill.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.db import models
from django.contrib.postgres.fields import ArrayField, JSONField
from django.contrib.postgres.search import SearchVectorField
from django.utils.encoding import python_2_unicode_compatible

from opencivicdata.core.models.base import (OCDBase, LinkBase, OCDIDField,
Expand Down Expand Up @@ -208,3 +209,36 @@ class BillSource(LinkBase):

class Meta:
db_table = 'opencivicdata_billsource'


class SearchableBill(models.Model):
"""
This model associates a single version's text with a given bill.
This is done for a few reasons:
* bills with multiple versions aren't weighted more heavily than others
* this makes querying quite a bit more efficient (no need to deduplicate results)
We'll also store error results, assuming that they're somewhat persistent.
"""
bill = models.OneToOneField(
Bill,
related_name="searchable",
null=True,
on_delete=models.CASCADE
)
version_link = models.OneToOneField(
BillVersionLink,
related_name="searchable",
on_delete=models.CASCADE
)

search_vector = SearchVectorField(default=None)
all_titles = models.TextField(default="")
raw_text = models.TextField(default="")
is_error = models.BooleanField(default=False)

created_at = models.DateTimeField(auto_now_add=True)

class Meta:
db_table = 'opencivicdata_searchablebill'
2 changes: 1 addition & 1 deletion setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
extras_require[":python_version<='2.7'"] = ["backports.csv"]

setup(name="opencivicdata",
version='2.3.0',
version='2.4.0',
author="James Turk",
author_email='[email protected]',
license="BSD",
Expand Down

0 comments on commit ff7e3b5

Please sign in to comment.