Javascript 文本搜索的行为

Javascript 文本搜索的行为,javascript,node.js,mongodb,mongoose,Javascript,Node.js,Mongodb,Mongoose,我用MONGOOSE应用程序在我的NodeJ中实现了MongoDB文本搜索,如果我搜索某个东西,那么结果有时对我来说没有意义 有人能解释一下文本搜索的行为吗? 我做错了什么 我有一个名字叫“弗兰兹”-我搜索“弗兰兹”-没有结果 我有一个名字叫“你是个英雄”-我搜索“英雄”-找到它 其他字段也一样-有时找到条目,有时不找到 CommentSchema.index({name:'text',shortDescription:'text',longDescription:'text',"topics.

我用MONGOOSE应用程序在我的NodeJ中实现了MongoDB文本搜索,如果我搜索某个东西,那么结果有时对我来说没有意义

有人能解释一下文本搜索的行为吗? 我做错了什么

我有一个名字叫“弗兰兹”-我搜索“弗兰兹”-没有结果 我有一个名字叫“你是个英雄”-我搜索“英雄”-找到它 其他字段也一样-有时找到条目,有时不找到

CommentSchema.index({name:'text',shortDescription:'text',longDescription:'text',"topics.text":'text',geoAreaGeneral:'text',geoAreaSpecific:'text'});
顺便说一句:主题索引(由
主题:[{}]
定义)不起作用-如何使其起作用

这是我的代码:

  var queryParamFind = {
    "addedDate" : {$lt:dateTimeISO}, 
    'deleted': {$ne:true}
  };

    if(order.includes("addedDate"))
    {queryParamOrder = {"addedDate" : -1}}
    if(order.includes("featured"))
    {queryParamOrder = {"featured" : -1}}
    if(order.includes("upvotes"))
    {queryParamOrder = {"upvotes" : -1}}
    else
    {queryParamOrder = {"addedDate" : -1}}

    if(searchPhrase != 'undefined'){
      if (searchPhrase.length==0)
      {}
      else
      {
      queryParamOrder= { "score": { "$meta": "textScore" } };
      queryParamFind= { "$text": { "$search": searchPhrase  }, 'deleted': {$ne:true}};
      queryParamSelect = { "score": { "$meta": "textScore" } };   
      }

    };

  Comment.find(queryParamFind)
        .select(queryParamSelect)
        .populate("addedBy")
        .sort(queryParamOrder)
        .limit(page * onePage)
        .exec(function(err, result){
    if(err){ return next(err); }
    res.json(result);
  });
例如:

{
    "_id": ObjectId("588dd5be93ca1b09003cf41a"),
    "number": NumberInt(1015),
    "addedBy": ObjectId("586e17f808612e10dcdcdc35"),
    "name": "This is a new comment",
    "shortDescription": "Please find me",
    "longDescription": "Please find me",
    "geoAreaGeneral": "Europe",
    "geoAreaSpecific": "Specific geo area",
    "creationDate": "2222-12-29T23:00:00.000Z",
    "updatedDate": ISODate("2017-01-29T11:45:02.585+0000"),
    "addedDate": ISODate("2017-01-29T11:45:02.585+0000"),
    "topics": [{
        "text": "Tag1"
    }, {
        "text": "Tag2"
    }],
    "__v": NumberInt(0)
} {
    "_id": ObjectId("588dd5df93ca1b09003cf41b"),
    "number": NumberInt(1016),
    "addedBy": ObjectId("586e17f808612e10dcdcdc35"),
    "name": "Hello my name is",
    "shortDescription": "Hello my name is",
    "longDescription": "Hello my name is",
    "geoAreaGeneral": "North America",
    "creationDate": "2222-02-11T23:00:00.000Z",
    "upvotes": NumberInt(0),
    "clicksCount": NumberInt(0),
    "updatedCount": NumberInt(0),
    "updatedDate": ISODate("2017-01-29T11:45:35.343+0000"),
    "addedDate": ISODate("2017-01-29T11:45:35.343+0000"),
    "topics": [{
        "text": "Tag4"
    }, {
        "text": "Tag1000"
    }],
    "__v": NumberInt(0)
} {
    "_id": ObjectId("588dd62093ca1b09003cf41c"),
    "number": NumberInt(1017),
    "addedBy": ObjectId("586e17f808612e10dcdcdc35"),
    "name": "My name is Hello",
    "shortDescription": "Fiind me via my short description",
    "longDescription": "Fiind me via my long description",
    "geoAreaGeneral": "North America",
    "updatedDate": ISODate("2017-01-29T11:46:40.956+0000"),
    "addedDate": ISODate("2017-01-29T11:46:40.956+0000"),
    "topics": [{
        "text": "Tag3000"
    }],
    "__v": NumberInt(0)
}
当我搜索“你好”-我只看到“你好,我的名字是”条目

当我寻求“评论”时——什么都没有

当我搜索“请查找”-查找“这是一条新评论”条目时

当我搜索“Fiind”时,会找到“我的名字是hello”

当我搜索“北方”-什么都没有

获取索引:

> [
>         {
>                 "v" : 2,
>                 "key" : {
>                         "_id" : 1
>                 },
>                 "name" : "_id_",
>                 "ns" : "main.comments"
>         },
>         {
>                 "v" : 2,
>                 "unique" : true,
>                 "key" : {
>                         "number" : 1
>                 },
>                 "name" : "number_1",
>                 "ns" : "main.comments",
>                 "background" : true
>         },
>         {
>                 "v" : 2,
>                 "key" : {
>                         "_fts" : "text",
>                         "_ftsx" : 1
>                 },
>                 "name" : "shortDescription_text_longDescription_text_topics_text",
>                 "ns" : "main.comments",
>                 "background" : true,
>                 "weights" : {
>                         "longDescription" : 1,
>                         "shortDescription" : 1,
>                         "topics" : 1
>                 },
>                 "default_language" : "english",
>                 "language_override" : "language",
>                 "textIndexVersion" : 3
>         } ]
> 

你能在帖子中添加一些示例文档和输入值吗?请将其添加到问题中不能添加到问题中-告诉我太长-请查看下面的我的答案我已经将其添加到问题中。你可以删除你的答案。我厌倦了你的搜索,它按照你期望的方式工作。你的mongo版本是什么?我的是3.2Hi!谢谢添加!我的是3.4!所以当你搜索“North”时,它实际上会找到一些东西,或者当你搜索“Hello”时,你会找到两个文档?