0

First I was using models.TextField, but it doesn't support indexing. Switching to models.CharField didn't help as text size was greater than 50000 characters in some rows. Indexing is allowed for maximum 3072 bytes data in MySQL. Should I switch to another RDBMS or use NoSQL like MongoDB? I also tried to use haystack with whoosh for indexing and searching, but searching was very slow.

Utkarsh Garg
  • 125
  • 1
  • 2
  • 12
  • you can use Postgresql (9.2+) which has [full text search](https://www.postgresql.org/docs/current/static/textsearch.html) capability or you can use a search backend like [elasticsearch](https://medium.freecodecamp.com/elasticsearch-with-django-the-easy-way-909375bc16cb) or [solr](http://www.alexanderinteractive.com/blog/2012/08/getting-started-with-solr-and-django/). – doru May 18 '17 at 12:13

1 Answers1

0

You should add a Full-Text index, and use the MySQL MATCH ... AGAINST ... Query

For example:

ALTER TABLE my_table ADD FULLTEXT `myTextColumn` (`myTextColumn`(50000));
SELECT * FROM my_table WHERE MATCH (`myTextColumn`) AGAINST ('tex*' IN BOOLEAN MODE);

What this does is: It creates a Full Text index on your column 'myTextColumn' And then it selects everything where the 'myTextColumn` contains the string 'tex'.

Full text search has limitations, and oddities but this is a good place to start if you don't want to switch database engines.

You can find more information about full text searches here for the MySQL database engine

Florian Humblot
  • 1,121
  • 11
  • 29