Skip to content

Instantly share code, notes, and snippets.

View mchernyavskaya's full-sized avatar

Maryna Cherniavska mchernyavskaya

View GitHub Profile
fun travelToRome(cities: Array<Int>): Int {
val destinationIndex = cities.size - 1
var index = 0
var days = 1
while ((index + cities[index]) < destinationIndex) {
val windowStart = 1
val windowEnd = cities[index]
var maxIndex = windowStart
// where I can jump from window start
var maxPos = cities[windowStart] + windowStart
We can make this file beautiful and searchable if this error is corrected: It looks like row 10 should actually have 3 columns, instead of 2. in line 9.
Features,MongoDb Text Search,Lucene
Term search,Yes,Yes
Phrase search,Yes (put the phrase in double quotes (backslashed): “\”native accused\””),Yes
OR search,Yes (Just type the two terms in a query: “native accused”),Yes (there’s an “OR” or just the space between the terms)
AND search,Yes (if you quote each of the terms as in phrase search that will work like an “AND” query),Yes (there’s an “AND” operator or a + operator which means that the word is required)
NOT search,Yes (add a “-” in front of the negated word),Yes (there’s a “NOT” operator and a “-” which works the same way)
Grouping,No,The terms can be grouped by parentheses like:(one two) AND three which means either “one” or “two” should be in the text and “three” is required
Wildcard searches,No (not in the text index. There’s a regex search though which can be used for the purpose),Yes (“*” and “?” are applied)
Fuzzy searches,No,Yes (tilde notation is used. “roam”~ means “find me all the items containing a word similar to roam”)
Proximity searches,No
db.movies.find( { $text: { $search: "\"cafe\" \"restaurant\"" }, "imdb.rating": { $ne: "" } }, { "title": 1, "plot": 1, "fullplot": 1, "genres": 1, "cast": 1, "imdb.rating": 1, "_id": 0 }). limit(5).sort({ "imdb.rating": -1 })
[
{
plot: 'A famous jazz saxophonist whose life is forever changed after he is accidentally shot.',
genres: [ 'Drama', 'Music', 'Mystery' ],
cast: [ 'Harvey Keitel', 'Richard Edson', 'Don Byron', 'Kevin Corrigan' ],
title: 'Lulu on the Bridge',
fullplot: 'A jazz saxophonist loses his capability to play when he is injured in a shooting at a cafè where he was playing. He sinks into depression when everyone charges in to take care of him, including his ex-wife. However, he discovers a stone with a telephone number attached. Returning the stone, he meets a young aspiring actress who in one of those film coincidences is listening to his music. Soon the two begin an affair which is fouled by his over-obsessiveness with her which costs them both a job at a restaurant.',
db.movies.find( { $text: { $search: "\"harry potter\"" }, "imdb.rating": { $ne: "" } }, { "title": 1, "plot": 1, "fullplot": 1, "genres": 1, "cast": 1, "imdb.rating": 1, "_id": 0 }). limit(5).sort({ "imdb.rating": -1 })
[
{
plot: "Harry, Ron and Hermione search for Voldemort's remaining Horcruxes in their effort to destroy the Dark Lord as the final battle rages on at Hogwarts.",
genres: [ 'Adventure', 'Drama', 'Fantasy' ],
cast: [
'Ralph Fiennes',
'Michael Gambon',
'Alan Rickman',
'Daniel Radcliffe'
parsedTextQuery: {
terms: [ 'harri', 'potter' ],
negatedTerms: [],
phrases: [],
negatedPhrases: []
}
db.movies.find( { $text: { $search: "harry potter" }, "imdb.rating": { $ne: "" } }, { "title": 1, "plot": 1, "fullplot": 1, "genres": 1, "cast": 1, "imdb.rating": 1, "_id": 0 }). limit(5).sort({ "imdb.rating": -1 })
[
{
plot: 'A comprehensive survey of the American Civil War.',
genres: [ 'Documentary', 'History', 'War' ],
cast: [
'Sam Waterston',
'Julie Harris',
'Jason Robards',
'Morgan Freeman'
@mchernyavskaya
mchernyavskaya / harry-potter-1.js
Created October 3, 2022 12:31
harry-potter-1-mongo
db.movies.find( { $text: { $search: "harry potter" }, "imdb.rating": { $ne: "" } }, { "title": 1, "plot": 1, "genres": 1, "imdb.rating": 1, "_id": 0 }). limit(5).sort({ "imdb.rating": -1 })
[
{
plot: 'A comprehensive survey of the American Civil War.',
genres: [ 'Documentary', 'History', 'War' ],
title: 'The Civil War',
imdb: { rating: 9.4 }
},
{
plot: 'A comprehensive survey of the American Civil War.',
db.movies.find(
{$text: {$search: "drama -action -crime"}, "imdb.rating": {$ne: ""}},
{"title": 1, "plot": 1, "genres": 1, "imdb.rating": 1, "_id": 0})
.limit(5)
.sort({ "imdb.rating": -1 }
)
[
{
plot: 'Ten television drama films, each one based on one of the Ten Commandments.',
genres: [ 'Drama' ],
db.movies.find(
{$text: {$search: "drama"}, "imdb.rating": {$ne: ""}},
{"title": 1, "plot": 1, "genres": 1, "imdb.rating": 1, "_id": 0})
.limit(5)
.sort({ "imdb.rating": -1 }
)
[
{
plot: 'The story of Easy Company of the US Army 101st Airborne division and their mission in WWII Europe from Operation Overlord through V-J Day.',
genres: [ 'Action', 'Drama', 'History' ],
db.movies.find(
{"imdb.rating": {$ne: ""}},
{"title": 1, "plot": 1, "genres": 1, "imdb.rating": 1, "_id": 0})
.limit(5)
.sort({ "imdb.rating": -1 })