【问题标题】:Example domain class for a Web Crawler Using Grails and MongoDB?使用 Grails 和 MongoDB 的 Web 爬虫的示例域类?
【发布时间】:2014-06-24 20:14:25
【问题描述】:

我正在使用 Groovy on Grails 和后端的 MongoDB 制作网络爬虫。我不确定如何为域类建模。

例如:

域类网站包含用户已预先保存并希望抓取的网站。 模型网站包含:www.google.com 抓取 www.google.com 后,我得到以下信息:

www.a.com   resource types  other metrics
www.b.com   resource types  other metrics
www.c.com   resource types  other metrics
www.d.com   resource types  other metrics

我想将它们存储在数据库中并继续爬取。同样,www.a.com 在被抓取时会产生更多的网址,例如:

www.a1.com  resource types  other metrics
www.a2.com  resource types  other metrics

对于所有其他 url,它们也会有子 URL。如何为它建模域类?我的一个想法是有一个域类(将与自身关联)如下,但我不确定它是否正确:

    class Resource implements Comparable { 
       String url
       String otherMetrics
       SortedSet subResources
       static hasMany = [subResources: Resource]
       static belongsTo = [parent: Resource]
}

【问题讨论】:

  • 投反对票的人请给出你投反对票的理由

标签: mongodb grails dns web-crawler


【解决方案1】:

我认为您的代码不起作用,因为您忘记了 mappedBy 部分:

你可能需要下一行来让它工作:

static mappedBy = [subResources:'parent']

最后,它是一棵树,我对这类问题使用相同的方法。

希望这会有所帮助。

【讨论】:

  • 很高兴知道其他人对这个问题有同样的方法。谢谢。我会试试这个:)
猜你喜欢
  • 2019-11-07
  • 1970-01-01
  • 2010-11-29
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2016-05-31
  • 2010-10-30
  • 2018-08-13
相关资源
最近更新 更多