Skip to content

A community-supported supercharged document management system: scan, index and archive all your documents

Allow to create case sensitive matches

Cku2c8e2661810d
diff --git a/src/documents/migrations/0015_add_insensitive_to_match.py b/src/documents/migrations/0015_add_insensitive_to_match.py
new file mode 100644
index 000000000..34a570c6e
--- /dev/null
+++ b/src/documents/migrations/0015_add_insensitive_to_match.py
@@ -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),
+ ),
+ ]
diff --git a/src/documents/models.py b/src/documents/models.py
index d4659c57e..c65e5f351 100644
--- a/src/documents/models.py
+++ b/src/documents/models.py
@@ -47,6 +47,8 @@ class MatchingModel(models.Model):
)
)
+ is_insensitive = models.BooleanField(default=True)
+
class Meta(object):
abstract = True
@@ -71,27 +73,32 @@ class MatchingModel(models.Model):
def matches(self, text):
+ search_kwargs = {}
+
# Check that match is not empty
if self.match.strip() == "":
return False
+ if self.is_insensitive:
+ search_kwargs = {"flags": re.IGNORECASE}
+
if self.matching_algorithm == self.MATCH_ALL:
for word in self.match.split(" "):
- if not re.search(r"\b{}\b".format(word), text):
+ if not re.search(r"\b{}\b".format(word), text, **search_kwargs):
return False
return True
if self.matching_algorithm == self.MATCH_ANY:
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 False
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:
- return bool(re.search(re.compile(self.match), text))
+ return bool(re.search(re.compile(self.match), text, **search_kwargs))
raise NotImplementedError("Unsupported matching algorithm")