V
V
Vlad Timofeev2015-01-20 23:34:54
MongoDB
Vlad Timofeev, 2015-01-20 23:34:54

How to do an adequate text search in MongoDB?

Hello, I'm doing a search on express + mongoose.
There is a schema and setting indexes:

var postSchema = mongoose.Schema({
    access: Boolean,
    readed: Boolean,
    title: String,
    num: Number,
    tags: [String],
    text: String,
    author: {
        idNum: Number
    },
    addtime: String,
    comments: [],
    reviews: Number
});


postSchema.plugin(require('mongoose-paginate'));
postSchema.index({ title: 'text', tags: 'text', text: 'text'});

There is a finished post:
{
    "_id" : ObjectId("54beaa0a73ddc8e822708cd3"),
    "addtime" : "20.1.2015",
    "reviews" : 0,
    "readed" : true,
    "text" : "SomeTagSomeTagSomeTag",
    "num" : 2,
    "title" : "SomeTagSomeTag",
    "access" : true,
    "comments" : [],
    "author" : {
        "idNum" : 1
    },
    "tags" : [ 
        "SomeTag"
    ],
    "__v" : 0
}

I wrote this in the routes:
Post.paginate({'access':true, 'text':{'search':req.body.call}}, req.query.page, req.query.limit, callback);// тут я все писать не буду, не важно дело.

And when I request a search with the SomeTag value (or in lowercase) - this post gives me.
But, when I write 'Some' or 'SomeTagSomeTag'(this is the title) - an empty array is returned :((
How can I fix this?
I would be grateful for your help..

Answer the question

In order to leave comments, you need to log in

1 answer(s)
E
Eugene, 2015-01-20
@PyTiMa

this is very easy to fix, you just need to throw out this shit and use specialized tools
sphinxsearch.com
elasticsearch.com

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question