Repository: dag-hammarskjold-library/dlx

Issue:
Logical field wildcard serarch bugfix
The search is not working properly matching strings at the beginning of the value, i.e. `author:german*`. Addresses https://github.com/dag-hammarskjold-library/dlx-rest/issues/1522

Discussion:

Solution patch:
diff --git a/dlx/marc/query.py b/dlx/marc/query.py
index 9d329515..ec80b969 100644
--- a/dlx/marc/query.py
+++ b/dlx/marc/query.py
@@ -15,7 +15,7 @@ class InvalidQueryString(Exception):
 class WildcardRegex(Regex):
     # for differentiating regex to run against text index vs actual value
     def __init__(self, string=None):
-        super().__init__(string, 'i')
+        super().__init__(string)
     
 class Query():
     @classmethod
@@ -96,7 +96,7 @@ def process_string(string):
                 string = string.replace('*', placeholder)
                 string = re.escape(string)
                 string = string.replace(placeholder, '.*')
-                string = string if string[0:2] == '.*' else '^' + string
+                string = string if string[0:2] == '.*' else '^ ' + string # the "text" field in pseudo indexes starts with a space 
                 string = string if string[-2:] == '.*' else string + '$'
 
                 return WildcardRegex(string)
diff --git a/setup.py b/setup.py
index 8911c508..c44a8450 100644
--- a/setup.py
+++ b/setup.py
@@ -1,4 +1,4 @@
-version = '1.4.13.1'
+version = '1.4.14'
 
 import sys
 from setuptools import setup, find_packages


Test patch:
diff --git a/tests/test_marc.py b/tests/test_marc.py
index 293a5554..f3538447 100644
--- a/tests/test_marc.py
+++ b/tests/test_marc.py
@@ -361,10 +361,13 @@ def test_querystring(db):
     query = Query.from_string(f'title:\'This title: is a title\'', record_type='bib')
     assert len(list(BibSet.from_query(query.compile()))) == 1
 
-    # logical field widldcard
+    # logical field wildcard
     query = Query.from_string(f"title:*is*", record_type='bib')
     assert len(list(BibSet.from_query(query.compile()))) == 3
 
+    query = Query.from_string(f"title:this*", record_type='bib')
+    assert len(list(BibSet.from_query(query.compile()))) == 2
+
     # NOT
     for bib in BibSet.from_query({}):
         # delete all bibs for further tests