MongoDB全文结果不一致

时间:2019-02-15 17:10:39

标签: mongodb full-text-search stemming

我将深入研究全文搜索功能,并且发现一些我无法解释的奇怪行为。

这是我运行的一个简单批处理,用于为测试设置数据库。

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" })

现在请注意,“女士”一词仅出现在第二个记录的“ zh”文本中。现在,我运行以下查询

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

不幸的是,这与表示“语言”字段仅_ 用于词干的文档不匹配,因此我认为所有搜索都应仅返回一个文档。

"$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"     

有人可以解释我在创建读取结果的索引时是否出错吗?

谢谢。

0 个答案:

没有答案