I'm going deep into full-text search features and i'm finding some strange behaviors I cannot explain.
Here is a simple batch I run to setup my db for the test.
use MusicDB
db.songs.insertMany([{
"rank": 1000,
"authors": ["Pink Floyd"],
"title": [
{ "language": "en", "text": "Comfortably numb" },
{ "language": "it", "text": "Piacevolmente insensibile" }
],
"text": [
{ "language": "en", "text": "Hello, Is there anybody in there? Just nod if you can hear me Is there anyone at home? Come on now I hear you're feeling down I can ease your pain And get you on your feet again Relax I'll need some information first Just the basic facts Can you show me where it hurts There is no pain, you are receding A distant ship smoke on the horizon You are coming through in waves Your lips move but I can't hear what you're saying When I was a child I had a fever My hands felt just like two balloons Now I've got that feeling once again I can't explain, you would not understand This is now how I am I have become comfortably numb O.K. Just a little pin prick There'll be no more aaaaaaaah! But you may feel a little sick Can you stand up? I do belive it's working, good That'll keep you going through the show Come on it's time to go. There is no pain you are receding A distant ship smoke on the horizon You are only coming through in waves our lips move but I can't hear what you're saying When I was a child I caught a fleeting glimpse Out of the corner of my eye I turned to look but it was gone I cannot put my finger on it now The child is grown The dream is gone And I have become Comfortably numb."},
{ "language": "it", "text": "Coraggio, lo so che ti senti triste. Posso alleviare il tuo dolore e rimetterti di nuovo in piedi. Rilassati. Prima di tutto ho bisogno di sapere senza troppi dettagli dove ti fa male. Il dolore è sparito, stai guarendo Il fumo di una nave lontana all'orizzonte stai risalendo onda dopo onda. Le tue labbra si muovono, ma io non riesco a sentire quello che stai dicendo. Da bambino ho avuto la febbre, le mie mani erano gonfie come palloni. Adesso avverto di nuovo quella senzazione, non riesco a spiegartelo, non riusciresti a capire. Questo non sono io. Sto diventando piacevolmente insensibile. Va bene, solo una punturina, e non piangerai più. Ma può darsi che avrai un po' di nausea, Ce la fai a stare in piedi? Penso che stia funzionando, bene. Questo ti terrà in piedi per tutto lo spettacolo. Dai, è ora di andare. Il dolore è sparito, si sta allontanando. Il fumo di una nave lontana all'orizzonte Stai risalendo onda dopo onda. Le tue labbra si muovono, ma io non riesco a sentire quello che stai dicendo. Da bambino colsi con la coda dell'occhio un rapido movimento. Mi girai a guardare, ma era sparito, non riescii a capire cosa fosse, adesso il bambino è cresciuto, il sogno è finito. e io sono diventato piacevolmente insensibile."}
]
},
{
"rank": 999,
"authors": ["Led Zeppelin"],
"title": [
{ "language": "en", "text": "Stairway to Heaven" },
{ "language": "it", "text": "Scalinata per il paradiso" }
],
"text": [
{ "language": "en", "text": "There's a lady who's sure all that glitters is gold And she's buying a stairway to heaven. When she gets there she knows, if the stores are all closed With a word she can get what she came for. Ooh, ooh, and she's buying a stairway to heaven. There's a sign on the wall but she wants to be sure 'Cause you know sometimes words have two meanings. In a tree by the brook, there's a songbird who sings, Sometimes all of our thoughts are misgiven. Ooh, it makes me wonder, Ooh, it makes me wonder. There's a feeling I get when I look to the west, And my spirit is crying for leaving. In my thoughts I have seen rings of smoke through the trees, And the voices of those who standing looking. Ooh, it makes me wonder,Ooh, it really makes me wonder. And it's whispered that soon if we all call the tune Then the piper will lead us to reason. And a new day will dawn for those who stand long And the forests will echo with laughter. If there's a bustle in your hedgerow, don't be alarmed now, It's just a spring clean for the May queen. Yes, there are two paths you can go by, but in the long run There's still time to change the road you're on. And it makes me wonder. Your head is humming and it won't go, in case you don't know, The piper's calling you to join him, Dear lady, can you hear the wind blow, and did you know Your stairway lies on the whispering wind. And as we wind on down the road Our shadows taller than our soul. There walks a lady we all know Who shines white light and wants to show How ev'rything still turns to gold. And if you listen very hard The tune will come to you at last. When all are one and one is all To be a rock and not to roll. And she's buying a stairway to Heaven."},
{ "language": "it", "text": "C'è una donna che crede che tutto cio che luccica sia oro Ha intenzione di comprare una scala per raggiungere il Paradiso E quando vi arriva sa, se i negozi sono chiusi, con una parola può avere ciò per cui è venuta qui Ooh, ooh, e sta comprando una scala per il paradiso. C'è una scritta sul muro, ma lei vuole essere sicura Perchè, lo sai, a volte le parole hanni due significati Su un albero vicino al ponte, c'è un uccellino che canta A volte, tutti i nostri pensieri sono sospetti. Ooh, e mi domando, Ooh, e mi domando. Quella sensazione che provo quando guardo verso Ovest E la mia anima grida di partire Nei miei pensieri ho visto spirali di fumo tra gli alberi. E le voci di quelli che stanno a guardare Ooh, e mi fa pensare, Ooh, e mi fa pensare. E si mormora che presto, se tutti canteremo la melodia il pifferaio ci guiderà alla ragione e un nuovo giorno spunterà per quelli che stavano aspettando da tanto E le foreste eccheggeranno di risate. Se c'è una via vai sul tuo sentiero, non ti allarmare Sono solo i preparativi per la reginetta di Maggio Si, ci sono due strade che puoi percorrere, ma alla fine farai ancora tempo a cambiare il tuo percorso. E mi fa pensare La tua testa canitcchia e quella melodia non se ne andrà, nel caso non lo sapessi, Il pifferaio ti sta chiamando, vuole che tu vada da lui. Dolce donna, senti il vento soffiare e lo sapevi che la tua scala poggia sui sussurri del vento. E mentre scendiamo lungo la strada e le nostre ombre sono più alte della nostra anima Là cammina una signora che noi tutti conosciamo che fa splendere una luce bianca e vuol mostrarci come tutto continui a tramutarsi in oro. E se ascolti molto attentamente Prima o poi la melodia giungerà a te Quando tutti sono uno e una cosa sola è tutto essere una roccia ma senza rotolare. E sta comprando una scala verso il Paradiso."}
]
}]);
db.songs.createIndex({ "title.text": "text", "text.text": "text" })
Now please notice that the word "lady" appears only one time into the "en" text of the second record. Now I runs the following queries
db.songs.find({ "$text": { "$search": "lady", "$language": "it" }})
// no occurrences found
db.songs.find({ "$text": { "$search": "lady", "$language": "en" }})
// one occurrence found
db.songs.find({ "$text": { "$search": "lady", "$language": "none" }})
// no occurrences found
Unfortunately this does not match the documentation that say "language" field is only_ used for stemming so I figure that all the searches should return exactly one document.
"$search": "lady" with "$language": "en"
// "lady" is stemmed to "ladi" so this match "lady" and "ladies"
"$search": "lady" with "$language": "it"
// "lady" is stemmed exactly to "lady" so this match "lady"
"$search": "lady" with "$language": "none"
// "lady" is not stemmed but tokenization results in "lady" so this match "lady"
Can someone explain if I'm going wrong in creating the index of in reading the results?
Thanks.
I'd like to parse a complex CSV file. I searched sources on the web but I only found readers for simple csv with coma and quote marks. But mine also contains "{", "[" and ":" in order to create groups, subgroups...
How can I retrieve a proper NSArray or a NSDictionary from this kind of csv ?
Or do you know a great (great !) csv reader/parser ?
Thanks !
Here is an example :
{"meta":{"code":200},"response":{"groups":[{"type":"nearby","name":"À
proximité","items":[{"id":"4bc88ad72f94d13aa9c5137f","name":"Métro
Chaussée d'Antin - La Fayette
[7,9]","contact":{},"location":{"address":"Métro
Chaussée d'Antin - La
Fayette","city":"Paris","state":"Île
de
France","postalCode":"75009","lat":48.872908,"lng":2.33325,"distance":39},"categories":[{"id":"4bf58dd8d48988d1fd931735","name":"Subways","icon":"http://foursquare.com/img/categories/travel/subway.png","parents":["Travel
Spots"],"primary":true}],"verified":false,"stats":{"checkinsCount":885,"usersCount":368},"hereNow":{"count":0}},{"id":"4ba8e508f964a520e4f739e3","name":"AdenClassifieds","contact":{},"location":{"address":"1-3
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8733461,"lng":2.3340489,"distance":50},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":187,"usersCount":29},"hereNow":{"count":0}},{"id":"4c10cd34b4aeef3bad5afc0f","name":"AdenSourcing","contact":{},"location":{"address":"1,
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.873009,"lng":2.333263,"distance":28},"categories":[{"id":"4bf58dd8d48988d125941735","name":"Tech
Startups","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"],"primary":true},{"id":"4bf58dd8d48988d174941735","name":"Coworking
Spaces","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"]}],"verified":false,"stats":{"checkinsCount":60,"usersCount":7},"hereNow":{"count":0}},{"id":"4b6d79c2f964a520f6762ce3","name":"Négatif+","contact":{},"location":{"address":"106
rue
lafayette","city":"Paris","state":"France","postalCode":"75010","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d1ff941735","name":"Miscellaneous
Shops","icon":"http://foursquare.com/img/categories/shops/default.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":121,"usersCount":51},"hereNow":{"count":0}},{"id":"4beeb21a2c082d7f96b53042","name":"Sephora
Haussmann","contact":{},"location":{"address":"23
bd
Hausmann","city":"Paris","state":"Ile-de-France","lat":48.8728835,"lng":2.3334661,"distance":41},"categories":[{"id":"4bf58dd8d48988d10c951735","name":"Cosmetics
Shops","icon":"http://foursquare.com/img/categories/shops/beauty_cosmetic.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":135,"usersCount":75},"hereNow":{"count":0}},{"id":"4af55e08f964a520f3f821e3","name":"Chez
Jean","contact":{},"location":{"address":"4
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8731558,"lng":2.3334978,"distance":13},"categories":[{"id":"4bf58dd8d48988d118951735","name":"Grocery
Stores","icon":"http://foursquare.com/img/categories/shops/food_grocery.png","parents":["Shops","Food and Drink
Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":46,"usersCount":27},"hereNow":{"count":0}},{"id":"4bee9a52e8c3c928dfd89892","name":"H&M","contact":{},"location":{"lat":48.872951,"lng":2.333551,"distance":35},"categories":[{"id":"4bf58dd8d48988d104951735","name":"Boutiques","icon":"http://foursquare.com/img/categories/shops/apparel.png","parents":["Shops","Clothing
Stores"],"primary":true}],"verified":false,"stats":{"checkinsCount":84,"usersCount":66},"hereNow":{"count":0}},{"id":"4b51d04df964a520865627e3","name":"Surcouf","contact":{},"location":{"address":"21,
bd
Haussmann","city":"Paris","state":"France","postalCode":"75009","lat":48.8728008,"lng":2.3339615,"distance":65},"categories":[{"id":"4bf58dd8d48988d122951735","name":"High
Tech
Outlets","icon":"http://foursquare.com/img/categories/shops/technology.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":332,"usersCount":194},"hereNow":{"count":0}},{"id":"4b1e6795f964a5209a1924e3","name":"Le
Manoir","contact":{},"location":{"address":"34
Boulevard
Haussmann","city":"Paris","state":"France","postalCode":"75009","lat":48.872964707066394,"lng":2.334015369415283,"distance":56},"categories":[{"id":"4bf58dd8d48988d16d941735","name":"Cafés","icon":"http://foursquare.com/img/categories/food/cafe.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":116,"usersCount":61},"hereNow":{"count":0}},{"id":"4cb59ee81b0af04dca42ca25","name":"Casa
Del
Campo","contact":{},"location":{"address":"Rue
Lafayette","city":"Paris","state":"Ile-de-France","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d1db931735","name":"Tapas
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":12,"usersCount":11},"hereNow":{"count":0}},{"id":"4cdd43c0d5495481874446b2","name":"Thalys
Paris >
Bruxelles","contact":{},"location":{"address":"111
rue
Lafayette","city":"Paris","state":"Ile-de-France","postalCode":"75011","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d12a951735","name":"Trains","icon":"http://foursquare.com/img/categories/travel/trainstation.png","parents":["Travel
Spots","Train
Stations"],"primary":true}],"verified":false,"stats":{"checkinsCount":5,"usersCount":5},"hereNow":{"count":0}},{"id":"4ba3d477f964a520226438e3","name":"Les
Diamantaires","contact":{},"location":{"address":"60,
Rue
Lafayette","city":"Paris","state":"Ile-de-France","postalCode":"75009","lat":48.873035,"lng":2.333235,"distance":26},"categories":[{"id":"4bf58dd8d48988d115941735","name":"Middle
Eastern
Restaurants","icon":"http://foursquare.com/img/categories/food/middleeastern.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":11,"usersCount":10},"hereNow":{"count":0}},{"id":"4cbeb94297bc721e31158167","name":"Dentiste","contact":{},"location":{"address":"36
bd
haussmann","city":"Paris","state":"Ile-de-France","lat":48.8729985,"lng":2.3331688,"distance":31},"categories":[{"id":"4bf58dd8d48988d178941735","name":"Dentist's
Offices","icon":"http://foursquare.com/img/categories/building/medical_dentist.png","parents":["Homes,
Work, Others","Medical
Centers"],"primary":true}],"verified":false,"stats":{"checkinsCount":9,"usersCount":2},"hereNow":{"count":0}},{"id":"4c098514bbc676b0365c48d5","name":"Best
Place To Be
Naked","contact":{},"location":{"lat":48.872859,"lng":2.333289,"distance":43},"categories":[],"verified":false,"stats":{"checkinsCount":36,"usersCount":21},"hereNow":{"count":0}},{"id":"4bbc55912d9ea5937878a0ce","name":"Pizza
Tivoli","contact":{},"location":{"address":"5
rue La
Fayette","city":"Paris","state":"France","postalCode":"75009","lat":48.8733461,"lng":2.3340489,"distance":50},"categories":[{"id":"4bf58dd8d48988d110941735","name":"Italian
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":62,"usersCount":47},"hereNow":{"count":0}},{"id":"4be11bf20f03a593908e18b4","name":"Pole
Direction Nvx
Medias","contact":{},"location":{"lat":48.872878,"lng":2.333277,"distance":42},"categories":[],"verified":false,"stats":{"checkinsCount":25,"usersCount":6},"hereNow":{"count":0}},{"id":"4c17d044834e2d7f94f02780","name":"Josefin","contact":{},"location":{"city":"Paris","state":"Ile-de-France","lat":48.872863,"lng":2.333273,"distance":43},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":14,"usersCount":8},"hereNow":{"count":0}},{"id":"4b597cfcf964a520e68928e3","name":"Siege
Danone","contact":{},"location":{"address":"17
boulevard
hausmann","city":"Paris","lat":48.873557,"lng":2.334042,"distance":59},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":23,"usersCount":13},"hereNow":{"count":0}},{"id":"4c1f5058fcf8c9b6f66bae0b","name":"Obene","contact":{},"location":{"address":"35
rue saint
lazarre","city":"Paris","state":"Francr","postalCode":"75009","lat":48.872829,"lng":2.333201,"distance":48},"categories":[{"id":"4bf58dd8d48988d1c0941735","name":"Mediterranean
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":21,"usersCount":5},"hereNow":{"count":0}},{"id":"4d5133ac9ffc236a026720a7","name":"Sofa
Cafe
Studio","contact":{},"location":{"lat":48.873568,"lng":2.33384,"distance":48},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":11,"usersCount":10},"hereNow":{"count":0}},{"id":"4cfa4adf2d80a1438a9f43d8","name":"Manucurist","contact":{},"location":{"address":"Rue
de la chausse d
antin","city":"Paris","state":"Ile-de-France","lat":48.87294352054596,"lng":2.333693504333496,"distance":41},"categories":[{"id":"4bf58dd8d48988d10c951735","name":"Cosmetics
Shops","icon":"http://foursquare.com/img/categories/shops/beauty_cosmetic.png","parents":["Shops"],"primary":true}],"verified":false,"stats":{"checkinsCount":28,"usersCount":4},"hereNow":{"count":0}},{"id":"4c7b90c9794e224bb48d6b28","name":"Le
Galfa - La
Fayette","contact":{},"location":{"lat":48.872853,"lng":2.333072,"distance":49},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":20,"usersCount":15},"hereNow":{"count":0}},{"id":"4c124b6377cea59338bccc60","name":"Noon","contact":{},"location":{"address":"Rue
de la chaussee d
antin","city":"Paris","state":"Ile-de-France","lat":48.8736428,"lng":2.3330026,"distance":51},"categories":[{"id":"4bf58dd8d48988d146941735","name":"Delis
or
Bodegas","icon":"http://foursquare.com/img/categories/food/deli.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":15,"usersCount":12},"hereNow":{"count":0}},{"id":"4bb2f78ea32876b0173a01fe","name":"Glam
Media France (temp
Offices)","contact":{},"location":{"address":"21
bd
Haussman","city":"Paris","lat":48.87305,"lng":2.333831,"distance":39},"categories":[{"id":"4bf58dd8d48988d125941735","name":"Tech
Startups","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others","Offices"],"primary":true}],"verified":false,"stats":{"checkinsCount":7,"usersCount":4},"hereNow":{"count":0}},{"id":"4c122cd7583c9c74bf323fa4","name":"Havaianas
welcomes Summer # Galeries
Lafayette","contact":{"phone":"0142823456","twitter":"havaianaseurope"},"location":{"address":"40
boulevard Haussmann","city":"75009
Paris","state":"France","country":"France","lat":48.8731566,"lng":2.3327878,"distance":44},"categories":[{"id":"4bf58dd8d48988d107951735","name":"Shoe
Stores","icon":"http://foursquare.com/img/categories/shops/apparel.png","parents":["Shops","Clothing
Stores"],"primary":true}],"verified":true,"stats":{"checkinsCount":11,"usersCount":9},"hereNow":{"count":0}},{"id":"4b9a40c4f964a52081a735e3","name":"little
georgette","contact":{},"location":{"lat":48.872544,"lng":2.33322,"distance":79},"categories":[{"id":"4bf58dd8d48988d10c941735","name":"French
Restaurants","icon":"http://foursquare.com/img/categories/food/default.png","parents":["Food"],"primary":true}],"verified":false,"stats":{"checkinsCount":60,"usersCount":41},"hereNow":{"count":0}},{"id":"4c319736213c2d7f5e33345d","name":"Isiom","contact":{},"location":{"lat":48.872815,"lng":2.333228,"distance":49},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":7,"usersCount":2},"hereNow":{"count":0}},{"id":"4c89f5e49ef0224b0595567b","name":"Cardiweb","contact":{},"location":{"city":"Paris","state":"Ile-de-France","lat":48.873727,"lng":2.33362,"distance":55},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":5,"usersCount":3},"hereNow":{"count":0}},{"id":"4c507cf7991c20a18e014786","name":"Focus
Groups","contact":{},"location":{"lat":48.872982,"lng":2.33353,"distance":31},"categories":[{"id":"4bf58dd8d48988d124941735","name":"Offices","icon":"http://foursquare.com/img/categories/building/default.png","parents":["Homes,
Work,
Others"],"primary":true}],"verified":false,"stats":{"checkinsCount":1,"usersCount":1},"hereNow":{"count":0}}]}]}}
That looks like JSON, not CSV. Use this JSON Framework to parse the file: http://code.google.com/p/json-framework/