用于在Java中存储和搜索一百万条记录的集合应该使用哪个?

huangapple go评论59阅读模式
英文:

Which collection to use to store and search a million record in Java?

问题

我想知道在Java中用于存储和搜索来自数百万数据的字符串/数据的正确集合是什么?

  1. 假设您想要用于字符串。
  2. 假设您想要用于对象,并搜索多个值。

请注意,我正在寻找最佳性能以快速获得搜索结果的方法。我正在寻找能够做到这一点的Java集合。输入是任意字符串,不一定是排序过的。

英文:

I would like to know which is the right collection to be used in Java to store and search string/data from millions of data?

  1. Assume you want it for String.
  2. Assume you want it for objects, and search for multiple values.

Please note that I am looking for the best performance to quickly get the search result. I am looking for Java collection which can do this. Want to know the right collection that can be used. Input is an arbitrary string and not necessarily sorted.

答案1

得分: 2

实际上,如果你想在如此大的数据结构中进行搜索,Java中可用的任何集合都不足够,因为你需要将所有数据存储在内存中,这将需要非常强大的计算机来工作。

然而,针对你的问题已经存在解决方案,这就是全文搜索(Full Text Search)。

可以查看一下Apache Lucene或者Elasticsearch(它在内部使用了Apache Lucene)。

对于更简单的解决方案,你也可以使用任何关系型数据库,这也应该能达到目的。

英文:

Actually if you want to search in such large data structure, none of the available collections in java would be sufficient as you would need to store all the data in memory which would require really powerfull computer to work.

However there are existing solutions to you problem, which is called Full Text Search.

Take a look at Apache Lucene or Elasticsearch (which uses Apache Lucene under the hood)

For more simple solution you could also use any relational database which should also do the trick.

huangapple
  • 本文由 发表于 2020年10月14日 18:03:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/64350963.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定