Búsqueda de texto parcial y completo de MongoDB
Env:
MongoDB (3.2.0) con MongoSColección:
los usuariosCreación del índice de texto:
BasicDBObject keys = new BasicDBObject();
keys.put("name","text");
BasicDBObject options = new BasicDBObject();
options.put("name", "userTextSearch");
options.put("unique", Boolean.FALSE);
options.put("background", Boolean.TRUE);
userCollection.createIndex(keys, options); // using MongoTemplate
Documento:
{"nombre": "LEONEL"}Consultas:
db.users.find( { "$text" : { "$search" : "LEONEL" } } )
=> ENCONTRADOdb.users.find( { "$text" : { "$search" : "leonel" } } )
=> ENCONTRADO (caso de búsqueda Sensible es falso)db.users.find( { "$text" : { "$search" : "LEONÉL" } } )
=> ENCONTRADO (la búsqueda con diacriticSensitive es falsa)db.users.find( { "$text" : { "$search" : "LEONE" } } )
=> ENCONTRADO (búsqueda parcial)db.users.find( { "$text" : { "$search" : "LEO" } } )
=> NO ENCONTRADO (búsqueda parcial)db.users.find( { "$text" : { "$search" : "L" } } )
=> NO ENCONTRADO (búsqueda parcial)¿Alguna idea de por qué obtengo 0 resultados usando como consulta "LEO" o "L"?
Regex con Text Index Search no está permitido.
db.getCollection('users')
.find( { "$text" : { "$search" : "/LEO/i",
"$caseSensitive": false,
"$diacriticSensitive": false }} )
.count() // 0 results
db.getCollection('users')
.find( { "$text" : { "$search" : "LEO",
"$caseSensitive": false,
"$diacriticSensitive": false }} )
.count() // 0 results
Documentación de Mongo:
https://docs.mongodb.com/v3.2/text-search/https://docs.mongodb.com/manual/reference/operator/query/text/https://docs.mongodb.com/manual/core/index-text/https://jira.mongodb.org/browse/SERVER-15090