Custom Mysql Lookup for FULLTEXT Search Returns empy on test runs

2 views
Skip to first unread message

Gui Talarico

unread,
May 6, 2020, 7:21:16 PM5/6/20
to Django users
Hi everyone - I am sorry if this is not the right place or format to ask for this typo of help.
I have been trying to solve this issue for a while but have not had any luck.


I created a Custom Lookup to be able to do full text search on mysql:

```
# lookup
class Search(models.Lookup):
    lookup_name = "search"

    def as_mysql(self, compiler, connection):
        lhs, lhs_params = self.process_lhs(compiler, connection)
        rhs, rhs_params = self.process_rhs(compiler, connection)
        params = lhs_params + rhs_params
        return f"MATCH (%s) AGAINST (%s IN BOOLEAN MODE)" % (lhs, rhs), params


models.TextField.register_lookup(Search)
# Migrations
  from django.db import migrations, models

# Table details
table_name = "by_api_casesnapshot"
field_name = "text"
index_name = f"{table_name}_{field_name}_index"


class Migration(migrations.Migration):

    dependencies = [("by_api", "0033_add_tag_color")]

    operations = [
        migrations.CreateModel(...), # As auto-generated
        migrations.RunSQL(
            f"CREATE FULLTEXT INDEX {index_name} ON {table_name} ({field_name})",
            f"DROP INDEX {index_name} ON {table_name}",
        ),
    ]
```
The __search works fine, but I use it inside a test suite it returns empty.
Any help or feedback is appreciated

Details are here
Reply all
Reply to author
Forward
0 new messages