I am trying to implement FTS feature with node and mongdodb backend. In the search result, I would also like to project a new field, i.e the matched string in the document. This would give it a google like feel. Has anyone got ideas on this without having write lots of own custom functions?
The schema looks like this
var version = new mongoose.Schema({
name: String,
owner: String,
reviewer: String,
date_of_modification: Date,
comments: String,
hints: [String],
global: Boolean,
**content: { type: [String], index: true }**
version_no: Number,
});
var artifactSchema= new mongoose.Schema({
pid : String,
trashed : Boolean,
baseline : Number,
versions : [version],
});
I would like to create an index on the content field of Version model.
I know its a little late but recently I did it with MEAN+angucomplete AngularJS Query e.g. http://localhost:8080/api/search?s= Express Query
router.route('/search')
.get(function(req, res) {
Dept.aggregate(
{ $match : { 'Product.name' : new RegExp(query, 'gi') } },
{ $project : { name : 1, _id : 1, 'Product.name' : 1, 'Product._id' : 1} },
{ $unwind : "$Product" },
{ $group : {
_id : "$_id",
Category : { $addToSet : "$name"},
Product : { $push : "$Product"}
}}
)
});
Angucomplete Markup
<div angucomplete-alt id="depts"
placeholder="Click Here to Search across Whole Store"
pause="300"
selected-object="selectedDepts"
remote-url="http://localhost:8080/api/search?s="
remote-url-data-field="Departments"
remote-url-response-formatter="responseFormatted"
search-fields="name"
title-field="name"
minlength="1"
maxlength="20"
description-field="description"
override-suggestions="true"
match-class="highlight"
autocapitalize="on" autocorrect="off" autocomplete="off"
input-class="form-control form-control-small"
class="col-lg-8"
ng-pattern="/^[A-Za-z]+$/"
docs-search-input-focus
>
</div>