mongoosejs / mongoose-text-search Goto Github PK
View Code? Open in Web Editor NEWMongoDB 2.4 text search support for mongoose
MongoDB 2.4 text search support for mongoose
Given that this will sooner or later land in Mongoose, will things like populate
be available then?
Do you have any thoughts on how to handle the meta data that the text command returns (per object like score
or per query like stats
)?
Edit: I don't know much about the internals of Mongoose (query interface etc.) but from the top of my Head I'd love to do this:
Post.find({foo: 'bar'}).text('kitten').populate('comments').exec(function(err, posts) {
});
If text
is used with a String of length > 0 Mongoose uses the text
command internally and passes the options of find
as the filter
property. sort
is then of course ignored. But limit
on the other hand can then be passed to the text command as well.
Is there a way of indexing a document and linked document together?
For example, i have a schema "movie" with keywords in it but they are modeled as separate documents and referenced from movies. When i search i want the keyword metadata (name) to be included in the index.
Is this possible with this module?
Is there any way I can get more result. In database I have:
gehen
gehen
gehend
gehende
gehendem
gehenden
gehender
gehendes
gehengelassen
gehenkt
gehenkte
gehenktem
gehenkten
gehenkter
gehenktes
gehenlassen
gehenlasst
gehenließ
gehenließen
gehenließet
gehenlässt
Gehens
However, when I search for "gehen", it returns only "gehen" and "Gehens". Is there any way I could get more relevant results?
Any help would be very appreciated
Currently the only thing that can be passed is a string which will be used as the search
property for the text
command. Things like filter
, project
or limit
aren't possible. Similar question than #1: Are there plans to make this more Mongoose-like?
I have some difficult if I want apply the example code in an existing db.
Following your example i've write this code:
var url = require("url");
var express = require("express");
var app = express();
app.get("/", function(request, response, next) {
response.header("Access-Control-Allow-Origin", "*");
var mongoose = require('mongoose');
mongoose.connect('localhost', 'blomming');
var textSearch = require('mongoose-text-search');
var blommingSchema = mongoose.Schema({
name: String,
description: [String],
url: String,
price: String,
original_price: String,
currency: String,
photos: [{
first:String,
second:String
}],
quantity: String,
fbcomments: String,
shop: [{
id:String,
url:String,
items_url:String,
name:String,
image:String
}],
});
blommingSchema.plugin(textSearch);
blommingSchema.index({ description : 'text' });
var blommingDoc = mongoose.model('products', blommingSchema);
var options = {
limit: 10
}
blommingDoc.textSearch('specchio',options, function (err, output) {
if (err) throw err;
console.log(output);
return response.send(JSON.stringify({"success" : true, "data" : output}));
return response.end();
});
});
app.listen(1337, '127.0.0.1');
console.log('Server running at http://127.0.0.1:1337/');
I've runned a debug step by step and the problem is this.
If I use a callback similar to "Game.create({ name: 'Super Mario 64', tags: ['nintendo', 'mario', '3d'] }, function (err) {" the debug enter inside a function blommingDoc.textSearch. If I don't use this it doesn't enter inside. But i don't need to create stuff each time that i want to search something.
Also on your example code if I comment the create function the debug jump over and doesn't reach the textSearch function.
I'm a newbie of nodejs and mongodb so i'm sorry if the solution is trivial.
Could you help me ?
Thanks.
Why there is no skip options?
That is what I got when trying to run the provied example:
{ name: 'MongoError',
message: 'text search not enabled',
ok: 0,
errmsg: 'text search not enabled' }
Very useful plugin. Thanks!
Are there plans to support a offset and sort option? I would like to paginate full text search results based on a specified sort order.
For example if the text inside the database Yáñez and I type search for Yanez, will it find the string?
I have a already built old project on nodejs where I am using MongoDb to store data. Mongodb version is 2.4
The problem is I am running a text-search on a collection but it's never return anything which means console.log(arguments); never get print anything
It's to inform you guys that I am able to run db.socialposts.runCommand( "text", { search: "accessories",limit: 1 } ) on mongo terminal and getting results very fast
var options, search;
options = {
limit: 1
};
search = 'accessories';
console.log(search);
SocialPost.textSearch(search, options, function(err, out) {
console.log(arguments);
return true;
});
It's Schema is
var schema;
schema = new mongoose.Schema({
entity_id: {
type: mongoose.Schema.Types.ObjectId,
required: true
},
social_id: {
type: String,
required: true
},
type: {
type: String,
required: true
},
app: {
type: String,
required: true
},
date: {
type: Date,
required: true
},
url: {
type: String,
required: true
},
post: {
type: String
},
title: {
type: String
},
image: {
type: String
},
video: {
type: String
},
hashtags: [String]
}, {
strict: 'throw'
});
And Index is
schema.index({
type: 1,
social_id: 1
});
schema.index({
type: 1,
entity_id: 1,
date: 1
});
schema.index({
title: 'text',
post: 'text'
});
Since 2.6 the test
operator has been replaced with $text
I'm not sure if pagination is possible with mongoose-text-search.
In my local mongo 2.6, I put all the find options together using this from node/mongoose:
var query = Contact.find(findOpt);
query.count(function(err, count) {
query.skip((req.query.page-1)*numContactsPerPage).limit(numContactsPerPage).
exec('find', function(err, contacts) {
...
});
});
But now using conservative mongolab/mongohq mongo 2.4, I don't know how to do it.
Any suggestion? Thanks.
e.g.
search: function(req, res, next) {
MyModel.textSearch(req.params.searchstring, function(err, output) {
if(err) {
console.log(err);
}
res.json(_.map(output.results, function(r) {return r.obj} ));
})
}
will output no error string and never return if MyModel doesn't have any records.
Using:
$ mongod --version
db version v2.4.6
$ node --version
v0.10.17
I attempted to follow the example of:
gameSchema.plugin(textSearch);
But the only thing that worked for me was to run the schema through the plugin instead, after declaring extra statics such as:
gameSchema.statics = {
load: function (id, cb) {//code here}
};
textSearch(gameSchema);
My documents have the following object inside
"random": {
"coordinates": [
0.8316348162479699,
0.0699989115819335
],
"type": "Point"
}
but when I use
project: "-random"
the random field still shows.
Edit: it's not only that field, i tried projecting in reverse (only including the field I want like: "title") but random field and two others are still showing
A declarative, efficient, and flexible JavaScript library for building user interfaces.
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google ❤️ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.