mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 10:37:12 -04:00 
			
		
		
		
	Merge branch 'CkuT-case_sensitive_matches'
This commit is contained in:
		
						commit
						6d310f006c
					
				| @ -13,3 +13,9 @@ python-dotenv>=0.3.0 | |||||||
| python-gnupg>=0.3.8 | python-gnupg>=0.3.8 | ||||||
| pytz>=2015.7 | pytz>=2015.7 | ||||||
| gunicorn==19.6.0 | gunicorn==19.6.0 | ||||||
|  | 
 | ||||||
|  | # For the tests | ||||||
|  | pytest | ||||||
|  | pytest-django | ||||||
|  | pytest-sugar | ||||||
|  | tox | ||||||
|  | |||||||
							
								
								
									
										25
									
								
								src/documents/migrations/0015_add_insensitive_to_match.py
									
									
									
									
									
										Normal file
									
								
							
							
						
						
									
										25
									
								
								src/documents/migrations/0015_add_insensitive_to_match.py
									
									
									
									
									
										Normal file
									
								
							| @ -0,0 +1,25 @@ | |||||||
|  | # -*- coding: utf-8 -*- | ||||||
|  | # Generated by Django 1.10.2 on 2016-10-05 21:38 | ||||||
|  | from __future__ import unicode_literals | ||||||
|  | 
 | ||||||
|  | from django.db import migrations, models | ||||||
|  | 
 | ||||||
|  | 
 | ||||||
|  | class Migration(migrations.Migration): | ||||||
|  | 
 | ||||||
|  |     dependencies = [ | ||||||
|  |         ('documents', '0014_document_checksum'), | ||||||
|  |     ] | ||||||
|  | 
 | ||||||
|  |     operations = [ | ||||||
|  |         migrations.AddField( | ||||||
|  |             model_name='correspondent', | ||||||
|  |             name='is_insensitive', | ||||||
|  |             field=models.BooleanField(default=True), | ||||||
|  |         ), | ||||||
|  |         migrations.AddField( | ||||||
|  |             model_name='tag', | ||||||
|  |             name='is_insensitive', | ||||||
|  |             field=models.BooleanField(default=True), | ||||||
|  |         ), | ||||||
|  |     ] | ||||||
| @ -47,6 +47,8 @@ class MatchingModel(models.Model): | |||||||
|         ) |         ) | ||||||
|     ) |     ) | ||||||
| 
 | 
 | ||||||
|  |     is_insensitive = models.BooleanField(default=True) | ||||||
|  | 
 | ||||||
|     class Meta(object): |     class Meta(object): | ||||||
|         abstract = True |         abstract = True | ||||||
| 
 | 
 | ||||||
| @ -71,27 +73,36 @@ class MatchingModel(models.Model): | |||||||
| 
 | 
 | ||||||
|     def matches(self, text): |     def matches(self, text): | ||||||
| 
 | 
 | ||||||
|  |         search_kwargs = {} | ||||||
|  | 
 | ||||||
|         # Check that match is not empty |         # Check that match is not empty | ||||||
|         if self.match.strip() == "": |         if self.match.strip() == "": | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|  |         if self.is_insensitive: | ||||||
|  |             search_kwargs = {"flags": re.IGNORECASE} | ||||||
|  | 
 | ||||||
|         if self.matching_algorithm == self.MATCH_ALL: |         if self.matching_algorithm == self.MATCH_ALL: | ||||||
|             for word in self.match.split(" "): |             for word in self.match.split(" "): | ||||||
|                 if not re.search(r"\b{}\b".format(word), text): |                 search_result = re.search( | ||||||
|  |                     r"\b{}\b".format(word), text, **search_kwargs) | ||||||
|  |                 if not search_result: | ||||||
|                     return False |                     return False | ||||||
|             return True |             return True | ||||||
| 
 | 
 | ||||||
|         if self.matching_algorithm == self.MATCH_ANY: |         if self.matching_algorithm == self.MATCH_ANY: | ||||||
|             for word in self.match.split(" "): |             for word in self.match.split(" "): | ||||||
|                 if re.search(r"\b{}\b".format(word), text): |                 if re.search(r"\b{}\b".format(word), text, **search_kwargs): | ||||||
|                     return True |                     return True | ||||||
|             return False |             return False | ||||||
| 
 | 
 | ||||||
|         if self.matching_algorithm == self.MATCH_LITERAL: |         if self.matching_algorithm == self.MATCH_LITERAL: | ||||||
|             return bool(re.search(r"\b{}\b".format(self.match), text)) |             return bool(re.search( | ||||||
|  |                 r"\b{}\b".format(self.match), text, **search_kwargs)) | ||||||
| 
 | 
 | ||||||
|         if self.matching_algorithm == self.MATCH_REGEX: |         if self.matching_algorithm == self.MATCH_REGEX: | ||||||
|             return bool(re.search(re.compile(self.match), text)) |             return bool(re.search( | ||||||
|  |                 re.compile(self.match, **search_kwargs), text)) | ||||||
| 
 | 
 | ||||||
|         raise NotImplementedError("Unsupported matching algorithm") |         raise NotImplementedError("Unsupported matching algorithm") | ||||||
| 
 | 
 | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user