mirror of
				https://github.com/paperless-ngx/paperless-ngx.git
				synced 2025-10-31 02:27:10 -04:00 
			
		
		
		
	Fixes #45
This commit is contained in:
		
							parent
							
								
									eb01bcf98b
								
							
						
					
					
						commit
						1e7ece81ee
					
				| @ -273,11 +273,7 @@ class Consumer(object): | |||||||
|     def _store(self, text, doc): |     def _store(self, text, doc): | ||||||
| 
 | 
 | ||||||
|         sender, title, tags, file_type = self._guess_attributes_from_name(doc) |         sender, title, tags, file_type = self._guess_attributes_from_name(doc) | ||||||
|         tags = list(tags) |         relevant_tags = set(list(Tag.match_all(text)) + list(tags)) | ||||||
| 
 |  | ||||||
|         lower_text = text.lower() |  | ||||||
|         relevant_tags = set( |  | ||||||
|             [t for t in Tag.objects.all() if t.matches(lower_text)] + tags) |  | ||||||
| 
 | 
 | ||||||
|         stats = os.stat(doc) |         stats = os.stat(doc) | ||||||
| 
 | 
 | ||||||
|  | |||||||
| @ -23,9 +23,10 @@ class Command(Renderable, BaseCommand): | |||||||
|         self.verbosity = options["verbosity"] |         self.verbosity = options["verbosity"] | ||||||
| 
 | 
 | ||||||
|         for document in Document.objects.all(): |         for document in Document.objects.all(): | ||||||
|  | 
 | ||||||
|             tags = Tag.objects.exclude( |             tags = Tag.objects.exclude( | ||||||
|                 pk__in=document.tags.values_list("pk", flat=True)) |                 pk__in=document.tags.values_list("pk", flat=True)) | ||||||
|             for tag in tags: | 
 | ||||||
|                 if tag.matches(document.content): |             for tag in Tag.match_all(document.content, tags): | ||||||
|                 print('Tagging {} with "{}"'.format(document, tag)) |                 print('Tagging {} with "{}"'.format(document, tag)) | ||||||
|                 document.tags.add(tag) |                 document.tags.add(tag) | ||||||
|  | |||||||
| @ -86,7 +86,19 @@ class Tag(SluggedModel): | |||||||
|         return "{}: \"{}\" ({})".format( |         return "{}: \"{}\" ({})".format( | ||||||
|             self.name, self.match, self.get_matching_algorithm_display()) |             self.name, self.match, self.get_matching_algorithm_display()) | ||||||
| 
 | 
 | ||||||
|  |     @classmethod | ||||||
|  |     def match_all(cls, text, tags=None): | ||||||
|  | 
 | ||||||
|  |         if tags is None: | ||||||
|  |             tags = cls.objects.all() | ||||||
|  | 
 | ||||||
|  |         text = text.lower() | ||||||
|  |         for tag in tags: | ||||||
|  |             if tag.matches(text): | ||||||
|  |                 yield tag | ||||||
|  | 
 | ||||||
|     def matches(self, text): |     def matches(self, text): | ||||||
|  | 
 | ||||||
|         # Check that match is not empty |         # Check that match is not empty | ||||||
|         if self.match.strip() == "": |         if self.match.strip() == "": | ||||||
|             return False |             return False | ||||||
|  | |||||||
		Loading…
	
	
			
			x
			
			
		
	
		Reference in New Issue
	
	Block a user