<small id='QQrmt'></small><noframes id='QQrmt'>

      <tfoot id='QQrmt'></tfoot>
      <legend id='QQrmt'><style id='QQrmt'><dir id='QQrmt'><q id='QQrmt'></q></dir></style></legend>
      • <bdo id='QQrmt'></bdo><ul id='QQrmt'></ul>

      <i id='QQrmt'><tr id='QQrmt'><dt id='QQrmt'><q id='QQrmt'><span id='QQrmt'><b id='QQrmt'><form id='QQrmt'><ins id='QQrmt'></ins><ul id='QQrmt'></ul><sub id='QQrmt'></sub></form><legend id='QQrmt'></legend><bdo id='QQrmt'><pre id='QQrmt'><center id='QQrmt'></center></pre></bdo></b><th id='QQrmt'></th></span></q></dt></tr></i><div id='QQrmt'><tfoot id='QQrmt'></tfoot><dl id='QQrmt'><fieldset id='QQrmt'></fieldset></dl></div>

      当搜索中使用多个单词时,如何在 Lucene.net 中执行 AND 搜索?

      时间:2023-09-14
        <bdo id='7D6NV'></bdo><ul id='7D6NV'></ul>

        <legend id='7D6NV'><style id='7D6NV'><dir id='7D6NV'><q id='7D6NV'></q></dir></style></legend>

        1. <tfoot id='7D6NV'></tfoot>
            <tbody id='7D6NV'></tbody>
          • <i id='7D6NV'><tr id='7D6NV'><dt id='7D6NV'><q id='7D6NV'><span id='7D6NV'><b id='7D6NV'><form id='7D6NV'><ins id='7D6NV'></ins><ul id='7D6NV'></ul><sub id='7D6NV'></sub></form><legend id='7D6NV'></legend><bdo id='7D6NV'><pre id='7D6NV'><center id='7D6NV'></center></pre></bdo></b><th id='7D6NV'></th></span></q></dt></tr></i><div id='7D6NV'><tfoot id='7D6NV'></tfoot><dl id='7D6NV'><fieldset id='7D6NV'></fieldset></dl></div>

                <small id='7D6NV'></small><noframes id='7D6NV'>

                本文介绍了当搜索中使用多个单词时,如何在 Lucene.net 中执行 AND 搜索?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着跟版网的小编来一起学习吧!

                问题描述

                我正在使用 Lucene.net 来尝试了解如何在我的应用程序中实现它.

                I am playing around with Lucene.net to try and get a handle of how to implement it in my application.

                我有以下代码

                            .....
                            // Add 2 documents
                            var doc1 = new Document();
                            var doc2 = new Document();
                
                            doc1.Add(new Field("id", "doc1", Field.Store.YES, Field.Index.ANALYZED));
                            doc1.Add(new Field("content", "This is my first document", Field.Store.YES, Field.Index.ANALYZED));
                            doc2.Add(new Field("id", "doc2", Field.Store.YES, Field.Index.ANALYZED));
                            doc2.Add(new Field("content", "The big red fox jumped", Field.Store.YES, Field.Index.ANALYZED));
                
                            writer.AddDocument(doc1);
                            writer.AddDocument(doc2);
                
                            writer.Optimize();
                            writer.Close();
                
                            // Search for doc2
                            var parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_29, "content", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29));
                            var query = parser.Parse("big abcdefg test1234");
                            var searcher = new IndexSearcher(indexDirectory, true);
                            var hits = searcher.Search(query);
                
                            Assert.AreEqual(1, hits.Length());
                
                            var document = hits.Doc(0);
                
                            Assert.AreEqual("doc2", document.Get("id"));
                            Assert.AreEqual("The big red fox jumped", document.Get("content"));
                

                这个测试通过了,这让我有点沮丧.我认为这意味着 Lucene.Net 使用 OR 来搜索术语而不是 AND,但我找不到任何有关如何实际执行 AND 搜索的信息.

                This test passes, which dismays me a bit. I assume this means that Lucene.Net uses OR for searches between terms and not an AND, but I can't find any information on how to actually perform an AND search.

                我想要的最终结果是,如果有人搜索Matthew Anderson",我不希望它显示引用Matthew Doe"的文档,因为这与任何方式、形状或形式都不相关.

                The end result I am going for is if someone searches for "Matthew Anderson" I don't want it to bring up documents that refer to "Matthew Doe" , as that isn't relevant in any way, shape or form.

                推荐答案

                A.如果您要求所有单词都在文档中,但不要求单词是连续的并且按照您指定的顺序:查询

                A. If you require all words to be in a document but don't require the words to be consecutive and in the order you specify: The query

                +big +red
                

                匹配

                * the big red fox jumped
                * the red big fox jumped
                * the big fast red fox jumped
                

                但不匹配

                * the small red fox jumped
                

                B.如果你想匹配一个短语(即所有单词都需要;单词必须是连续的并且按照指定的顺序):查询

                B. If you want to match a phrase (i.e. all words required; the words have to be consecutive and in the order specified) instead: The query

                +"big red"
                

                匹配

                * the big red fox jumped
                

                但不匹配

                * the red big fox jumped
                * the big fast red fox jumped
                * the small red fox jumped
                

                这篇关于当搜索中使用多个单词时,如何在 Lucene.net 中执行 AND 搜索?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持跟版网!

                上一篇:Lucene IndexWriter 添加文档速度慢 下一篇:随着时间的推移,随着索引和文档数量的增加,elasticsearch 批量索引会变慢

                相关文章

              1. <legend id='rAVQZ'><style id='rAVQZ'><dir id='rAVQZ'><q id='rAVQZ'></q></dir></style></legend>
                <tfoot id='rAVQZ'></tfoot>

                <small id='rAVQZ'></small><noframes id='rAVQZ'>

              2. <i id='rAVQZ'><tr id='rAVQZ'><dt id='rAVQZ'><q id='rAVQZ'><span id='rAVQZ'><b id='rAVQZ'><form id='rAVQZ'><ins id='rAVQZ'></ins><ul id='rAVQZ'></ul><sub id='rAVQZ'></sub></form><legend id='rAVQZ'></legend><bdo id='rAVQZ'><pre id='rAVQZ'><center id='rAVQZ'></center></pre></bdo></b><th id='rAVQZ'></th></span></q></dt></tr></i><div id='rAVQZ'><tfoot id='rAVQZ'></tfoot><dl id='rAVQZ'><fieldset id='rAVQZ'></fieldset></dl></div>

                  <bdo id='rAVQZ'></bdo><ul id='rAVQZ'></ul>