davidtran999 commited on
Commit
285fdfa
·
verified ·
1 Parent(s): 8cb1bf9

Upload backend/core/management/commands/populate_legal_tsv.py with huggingface_hub

Browse files
backend/core/management/commands/populate_legal_tsv.py ADDED
@@ -0,0 +1,42 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
+ """
2
+ Management command to populate tsv_body (SearchVector) for LegalSection.
3
+ This is required for BM25 search to work.
4
+ """
5
+ from django.core.management.base import BaseCommand
6
+ from django.contrib.postgres.search import SearchVector
7
+ from hue_portal.core.models import LegalSection
8
+
9
+
10
+ class Command(BaseCommand):
11
+ help = "Populate tsv_body (SearchVector) for all LegalSection instances"
12
+
13
+ def handle(self, *args, **options):
14
+ self.stdout.write("Populating tsv_body for LegalSection...")
15
+
16
+ # Update all LegalSection instances with SearchVector
17
+ updated = LegalSection.objects.update(
18
+ tsv_body=SearchVector(
19
+ 'section_title',
20
+ weight='A',
21
+ config='simple'
22
+ ) + SearchVector(
23
+ 'section_code',
24
+ weight='A',
25
+ config='simple'
26
+ ) + SearchVector(
27
+ 'content',
28
+ weight='B',
29
+ config='simple'
30
+ ) + SearchVector(
31
+ 'excerpt',
32
+ weight='C',
33
+ config='simple'
34
+ )
35
+ )
36
+
37
+ self.stdout.write(
38
+ self.style.SUCCESS(
39
+ f"Successfully populated tsv_body for {updated} LegalSection instances"
40
+ )
41
+ )
42
+