glynnbird commented on issue #184: Error: Invalid operator: $regex
URL: https://github.com/apache/couchdb-nano/issues/184#issuecomment-537370120
 
 
   First of all the regex operator is very slow and an index can't be used to 
speed it up. It will inevitable cause CouchDB to do a full database scan 
(looking through each document body in turn) to get your answer. If you are 
looking for "all documents containing 'cat'" then you need to index each word 
in the string in question, which is what `type: 'text'` indexes are for. 
Unfortunately they are not baked into CouchDB today (stay tuned for CouchDB 3.0 
which should have free-text search baked in).
   
   Without the Lucene-based free-text search index, you're a bit stuck. You 
could roll your own index with a MapReduce index like so?:
   
   ```js
   function(doc) { 
     // break "str" into words
     var words = doc.str.split(/\W/); 
     for(var i in words) { 
        if (words[i]) { 
           // create an index with the lower-cased word as the key
          emit(words[i].toLowerCase(), null)
         }
      }
   }
   ```
   
   

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
[email protected]


With regards,
Apache Git Services

Reply via email to