How do I search for a phrase and a keyword at the same time in mongodb?
NickName:NewSQLguy Ask DateTime:2017-04-30T05:38:40

How do I search for a phrase and a keyword at the same time in mongodb?

Basically I'm going through a large yelp database in my mongodb, and I want to find all reviews with the phrase hot wings and keyword discount. But I can't create the right query that will look for the review that has the phrase hot wings AND the keyword discount in the review.

To give you some background, I imported several large json files of yelp review into my mongodb database on ubuntu. I want to look for keyword "UFC" under "text" and "Alcohol: full_bar" under attributes and return a count of them, at bare minimum. Because I want to see if bars that mentioned UFC and MMA get more reviews and checkins and tips than other bars, that do not mention those things.

I've built this index successfully in my mongodb database:

> db.collection.createIndex({"text":"text", "attributes": "text"})
{
    "createdCollectionAutomatically" : false,
    "numIndexesBefore" : 1,
    "numIndexesAfter" : 2,
    "ok" : 1
}

This is what I have:

db.collection.find( { $text: { $search: "\"hot wings\" 'discount'" } } )

So far it only gave me reviews with hot wings in there, and discount in there. Is there way to show only reviews contains phrase hot wing AND keyword discount?

And is there way to search for multiple phrases and a key word at the same time?

Copyright Notice:Content Author:「NewSQLguy」,Reproduced under the CC 4.0 BY-SA copyright license with a link to the original source and this disclaimer.
Link to original article:https://stackoverflow.com/questions/43700748/how-do-i-search-for-a-phrase-and-a-keyword-at-the-same-time-in-mongodb

More about “How do I search for a phrase and a keyword at the same time in mongodb?” related questions

How do I search for a phrase and a keyword at the same time in mongodb?

Basically I'm going through a large yelp database in my mongodb, and I want to find all reviews with the phrase hot wings and keyword discount. But I can't create the right query that will look for...

Show Detail

Mongodb exact phrase search

As I understood from Mongodb documentation of text search. if i want to search about Java or (coffee shop) I need to do it like {$text:{$search:"Java \"coffee shop\""}} Exact Phrase search in mong...

Show Detail

suggest search phrase based on inputted keyword

user can search keyword in my app and I want to suggest some phrases to him, which contain that keyword (generally like google). what I currently do is: 1. searching for the rows which contain the

Show Detail

MongoDB - $text operator search for phrase OR word(s)

I'm doing a full text search that requires phrase(s) OR word(s). As per the documentation: If the $search string includes a phrase and individual terms, text search will only match the documents t...

Show Detail

what is the effecient way to search a phrase in mongodb

What is the best way to search a phrase that have words that dont all matches, for example: description = "a cell phone that have an external memory" and i want to search: search = "a good phone...

Show Detail

How to search on mongodb mongoose ObjectId per keyword?

How to search on mongodb mongoose _id ObjectId per keyword? Example in mysql SELECT * FROM `table` WHERE `id` LIKE '%keyword%' How can i achieve that in mongodb?

Show Detail

How to make an Exact Phrase text-search in MongoDB using variable (and node.js)

I am trying to find a list of mongoDB documents based on exact phrase search. I want to first store exact phrase in a variable and then search for it by using text-search query. So far I have I have

Show Detail

How do I search for partial accented keyword in elasticsearch?

I have the following elasticsearch settings: "settings": { "index":{ "analysis":{ "analyzer":{ "analyzer_keyword":{ "

Show Detail

Keyword density calculation on a keyword phrase?

When attempting to calculate the keyword density of a single keyword in a string of content, the formula is pretty straightforward: kwd = (keyword count / total word count ) * 100 However, what sh...

Show Detail

Azure search - Searching for a phrase

I am using Azure Search within a .Net application to search across several fields over multiple documents. When searching for a phrase by quoting the search keyword (for example "software develope...

Show Detail