loopback icon indicating copy to clipboard operation
loopback copied to clipboard

How can i make a fulltext search on filter param ?

Open bluestaralone opened this issue 12 years ago • 14 comments

How can i make a fulltext search on filter param like mongodb said in the ducument: http://docs.mongodb.org/manual/reference/operator/query/text/ Please help me....thanks Example:

Book.search = function(text, callback) {
     var mongodb   = Book.getDataSource().connector.collection(Book.modelName);
      mongodb.find({ $text: { $search: "computer" }}, function(err, books){
            callback(null, books);
      });
});

bluestaralone avatar Oct 09 '14 07:10 bluestaralone

i'm done. Thanks god.

bluestaralone avatar Oct 10 '14 10:10 bluestaralone

What, how did you solve this?

offlinehacker avatar Oct 10 '14 10:10 offlinehacker

Something like

http://mysite.com/api/MongoModel?filter={"$text":{"$search":"california"}}

would be perfectly valid.

ffflabs avatar Oct 10 '14 15:10 ffflabs

Is it still working on the latest version? Or am I missing something?

MongoDB text index successfully created and I can run this directly in mongo, which works fine:

db.Job.find({ $text: { $search: "manager" } })

However running this API returning ALL results instead:

http://mysite.com/api/Jobs?filter={"$text":{"$search":"manager"}}

dmitriy-01 avatar Jun 03 '15 04:06 dmitriy-01

Actually, it doesn't work with loopback just for Collection.find

bluestaralone avatar Jun 03 '15 06:06 bluestaralone

How did you get this working?

playground avatar Sep 04 '15 22:09 playground

How did you get this working?

danielrvt avatar Jan 11 '16 20:01 danielrvt

If anyone is still looking to make this work. Was able to get this working on the latest connector code by tweaking the format of the clause.

{ where: { '$text': { search: "search term" } } }

This works because the connector will treat $text as a conditional and auto append $ to the search key.

apparentvisuals avatar Mar 26 '16 14:03 apparentvisuals

I don't know how you made that work, but I keep getting. { where: { '$text': { search: keyword } } }

---> MongoError: unknown operator: $$text If I get rid of the $ and just put text then ---> MongoError: unknown operator: $text And yes I do have indexes on my collection

bluermind avatar Oct 31 '17 09:10 bluermind

This call works for me http://localhost:3000/api/items?filter={"where":{"$text":{"search":"search term"}}} I hope this will help

ogermani avatar Nov 02 '17 13:11 ogermani

try adding "allowExtendedOperators": true on your datasources.json mongodb connector

b3rew avatar Nov 16 '17 07:11 b3rew

http://localhost:8080/api/Logs?filter[where][$text][search]=ERROR

myfreax avatar Jan 23 '18 08:01 myfreax

Hey guys I get back empty array on the search result. Do you know what's the problem? I have collection like this

{
    "description": "xxxx",
    "id": "5c11f7a00d12b470d915e609"
  },

I created a text index on it like this

db.Task.createIndex({ "$**": "text" })

And query it like this

{ "where": { "$text": { "search": "x"} } }

But all I get is an empty array.

hayk94 avatar Dec 17 '18 19:12 hayk94

@hayk94

      var tempCollection=db.Task
      tempCollection.createIndex({'$**': 'text'});
      var result =  tempCollection.find({$text: {$search: 'ccccc'}});
      result.toArray(function(err, doc) {
        console.log(doc);
      });

=====================

tempCollection save


{
name:"aaaa",
value:"ccccc"
}

===================== test result
search   c  is empty
search ccccc is exist

xcyxiner avatar Apr 10 '19 06:04 xcyxiner