在 vb.net 中使用 Lucene.net 的列表 (T)

发布于 2024-09-17 00:45:23 字数 1061 浏览 2 评论 0原文

我想使用列表来存储文档中的标题、路径...。

我这样声明该列表: Dim MyDocuments As New List(Of Document)

但我真的不知道如何处理该列表。 我想使用列表而不是 ReDim 数组。

For i = 0 To results - 1 Step 1 ' forschleife zum durchlaufen der Ergebnisse

                            Try


                                MyDocuments.Add(New Document())


                                array_results(i, 0) = hits.Doc(i).Get("title")
                                array_results(i, 0) += hits.Doc(i).Get("doc_typ") 
                                array_results(i, 1) = hits.Doc(i).Get("pfad")
                                'array_results(i, 2) = hits.Doc(i).Get("date_of_create") '
                                array_results(i, 2) = hits.Doc(i).Get("last_change")
                                array_results(i, 3) = CStr(hits.Score(i))
                                array_results(i, 4) = hits.Doc(i).Get("doc_typ")

我可以存储对象 Document,还是必须创建一个自己的类? 有使用列表的好教程吗? (我搜索过,但没有找到好的东西) (T) 的列表是正确的数据结构吗?

但我该如何做 mylist(i) -> gettitle() 或类似的事情?

提前致谢!

i want to use an List to store the title, path,... from Documents.

I declared the list like this:
Dim MyDocuments As New List(Of Document)

But i don't really know how to handle the list.
i want to use the list instead of an ReDim Array.

For i = 0 To results - 1 Step 1 ' forschleife zum durchlaufen der Ergebnisse

                            Try


                                MyDocuments.Add(New Document())


                                array_results(i, 0) = hits.Doc(i).Get("title")
                                array_results(i, 0) += hits.Doc(i).Get("doc_typ") 
                                array_results(i, 1) = hits.Doc(i).Get("pfad")
                                'array_results(i, 2) = hits.Doc(i).Get("date_of_create") '
                                array_results(i, 2) = hits.Doc(i).Get("last_change")
                                array_results(i, 3) = CStr(hits.Score(i))
                                array_results(i, 4) = hits.Doc(i).Get("doc_typ")

Can I store the object Document, or do i have to create an own class??
Is there a good tutorial for using the list? (i searched, but didn't found something good)
Is the List of (T) the right data structure?

but how can i do like mylist(i) ->gettitle() or something like this?

thanks in advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

埋情葬爱 2024-09-24 00:45:23

是的,您可以将文档存储在通用列表中。确定 List 是否是正确的数据结构取决于您想要用它做什么。也许如果您提供更多信息,有人可以提出更好的例子。我不懂 VB.NET 所以我会用 C# 来做。

// i assume you're using the Document class of Lucene.NET
List<Document> documents = new List<Document>();   

// add the documents to your collection
for (i = 0; i < hits.Length(); i++)
{
    // each result in the list contains a Document 
    // which you can add to your list
    documents.Add(hits.Doc(i));   
}

// you can search the list for a Document following a specific rule, using lambda expressions
Document myDoc = documents.Find(d => d.Get("title") == "a value");

// you can get a document by a specific index
Document myOtherDoc = documents[0];

// you can search the list for multiple Documents following a specific rule, using lambda expressions
List<Document> myDocs = documents.FindAll(d => d.Get("doc_typ") == "a type");

有关 List 的更多信息可在此处找到:http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

有关 lambda 表达式的更多信息,请访问:http://msdn.microsoft.com/en-us/library/bb397687.aspx

这篇关于 SO 的文章展示了如何使用 lambda 来搜索 List

Yes, you can store your documents in a generic List. Deciding if a List<T> is the right data structure or not depends on what you want to do with it. Maybe if you provide more information someone could come up with a better example. I don't know VB.NET so i'll do it in C#.

// i assume you're using the Document class of Lucene.NET
List<Document> documents = new List<Document>();   

// add the documents to your collection
for (i = 0; i < hits.Length(); i++)
{
    // each result in the list contains a Document 
    // which you can add to your list
    documents.Add(hits.Doc(i));   
}

// you can search the list for a Document following a specific rule, using lambda expressions
Document myDoc = documents.Find(d => d.Get("title") == "a value");

// you can get a document by a specific index
Document myOtherDoc = documents[0];

// you can search the list for multiple Documents following a specific rule, using lambda expressions
List<Document> myDocs = documents.FindAll(d => d.Get("doc_typ") == "a type");

More information about the List<T> can be found here: http://msdn.microsoft.com/en-us/library/6sh2ey19.aspx

More information on lambda expressions can be found here: http://msdn.microsoft.com/en-us/library/bb397687.aspx

This article on SO shows how to use lambdas to search a List<T>

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文