net搜索时多个单词在搜索中使用

net搜索时多个单词在搜索中使用

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

问题描述

我与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"));

这个测试通过,这dismays我有点。我认为,这意味着Lucene.Net用途或术语,而不是之间的搜索,但我无法找到如何实际执行和搜查任何信息。

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.

最终的结果我打算是,如果有人搜索马修·安德森我不希望它弹出引用马修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. 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. 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搜索时多个单词在搜索中使用?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-20 08:33