0

Each document consists of "name, city and branch" then they also contain "keywords" which is a combines version of "name, city and branch".

I now need a regular expression, this is what I got:

    public function searchLocation($keyword){
        $result = $this->locations->find(array('keywords' => new MongoRegex('/^' . strtolower($keyword) . '/')));

        if($result){
            return $result;
        }

        return false;
    }

Problem is, that when the user input was "grandcaffee london" it won't search for EACH word, or when the user inserts: "Cinema New York".

Thanks for reading.

1 Answer 1

1

You can do this (matches "grandcaffee" OR "london")

db.locations.find({keywords: {$in: [/grandcaffee/, /london/]}});

or this (matches documents with BOTH "grandcaffee" and "london")

db.locations.find({keywords: {$all: [/grandcaffee/, /london/]}});
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.