我正在使用MongoDB 1.6.3来存储大集合(300k +记录).我添加了一个复合索引.
db['collection_name'].getIndexes()
[
{
"name" : "_id_",
"ns" : "db_name.event_logs",
"key" : {
"_id" : 1
}
},
{
"key" : {
"updated_at.t" : -1,
"community_id" : 1
},
"ns" : "db_name.event_logs",
"background" : true,
"name" : "updated_at.t_-1_community_id_1"
}
]
Run Code Online (Sandbox Code Playgroud)
但是,当我尝试运行此代码时:
db['collection_name']
.find({:community_id => 1})
.sort(['updated_at.t', -1])
.skip(@skip)
.limit(@limit)
Run Code Online (Sandbox Code Playgroud)
我正进入(状态:
Mongo :: OperationFailure(没有索引的sort()数据太多.添加索引或指定更小的限制)
我究竟做错了什么?
我使用mongo存储日志文件.mongoDB和mysql都在同一台机器上运行,虚拟化mongo env不是一个选项.因为日志表变得非常快,我恐怕很快就会遇到性能问题.有没有办法限制mongo的常驻内存,以便它不会占用所有可用内存并过度减慢mysql服务器?
数据库机:Debian'lenny'5
其他解决方案(请评论):
由于我们需要所有历史数据,我们不能使用上限集合,但我也在考虑使用转储和删除旧数据的cron脚本
我应该考虑使用其他论坛上建议的较小的密钥吗?
在红宝石上,include
私有的原因是什么,而Object#extend
公众呢?
我想使用Solr + Sunspot来索引双语FR-EN网站.问题:模特邮政可以用法语或英语写成.我可以在运行时确定语言是什么,但我也需要Solr来相应地索引模型.
EG:对于法国模特,我需要一个法国干手,
<filter class="solr.SnowballPorterFilterFactory" language="French"/>
Run Code Online (Sandbox Code Playgroud)
我有什么选择?我可以在运行时更改Solr分析仪吗?我可以为每种语言制作一套分析仪吗?
solr full-text-search ruby-on-rails internationalization sunspot
有没有办法在运行时确定是否应该对模型编制索引?就像是:
class Article < ActiveRecord::Base
searchable :if => :indexable? do
...
end
private
def indexable?
...
end
end
Run Code Online (Sandbox Code Playgroud) 就像是:
get '/1.0/users/:id'
puts current_route_matcher.to_s # '/1.0/users/:id'
end
Run Code Online (Sandbox Code Playgroud)
需要让它为每种资源类型构建统计信息.
是否有相当于AR的命名范围?命名范围基本上是过滤器,可以包装在方法中,然后链接.
以下是http://archives.ryandaigle.com/articles/2008/8/20/named-scope-it-s-not-just-for-conditions-ya-know的示例:
class Article < ActiveRecord::Base
# Get all articles that have been published
named_scope :published, :conditions => ['published = ?', true]
# Get all articles that were created recently
named_scope :recent, lambda { { :conditions => ['created_at >= ?', 1.week.ago] } }
end
# Get all recently created articles that have been published
Article.published.recent
Run Code Online (Sandbox Code Playgroud)
以下是使用Django ORM的示例:http://furrybrains.com/2009/06/22/named-scopes-for-django/
我需要缓存(并过期)表中的所有模型.
例如,如果我有一个名为Currency的模型,我只有少于10种可能的货币.因此,最好有:
class Currency < ActiveRecord::Base
cache_all(:expire_in => 10.minutes)
end
Run Code Online (Sandbox Code Playgroud)
以便
Currency.all
Currency.find_by_name("USD")
Run Code Online (Sandbox Code Playgroud)
不应该打DB.
您认为这可能是一个好方法?
此外,如果您认为使用未由数据库备份的模型会更好,请对此进行评论.请注意,我希望有一个AR风格的协会.
我正在使用各种XML-over-HTTP Web服务返回大型XML文件(> 2MB).什么是最快的ruby http库来减少'下载'时间?
所需功能:
GET和POST请求
gzip/deflate downloads(Accept-Encoding: deflate, gzip
) - 非常重要
我在考虑:
开放式的URI
网:: HTTP
抑制
但你也可以提出其他建议.
PS要解析响应,我使用Nokogiri的pull解析器,所以我不需要像rest-client或hpricot这样的集成解决方案.
我正在尝试复制一些动态字段以进行拼写检查.然而 .以下是schema.xml中的相关字段:
<dynamicField name="*_text_fr" stored="false" type="text_fr" multiValued="true" indexed="true"/>
<dynamicField name="*_text_frs" stored="true" type="text_fr" multiValued="true" indexed="true"/>
<dynamicField name="*_text_frms" stored="true" type="text_fr" multiValued="true" indexed="true"/>
Run Code Online (Sandbox Code Playgroud)
它不会复制任何东西:
<copyField source="*_text_fr*" dest="textSpellFr" />
Run Code Online (Sandbox Code Playgroud)
但是,它适用于:
<copyField source="*_text_fr" dest="textSpellFr" />
<copyField source="*_text_frs" dest="textSpellFr" />
<copyField source="*_text_frms" dest="textSpellFr" />
Run Code Online (Sandbox Code Playgroud)
为什么第一个选项不起作用?
假设我们有一个由sunspot/solr/lucene(或任何其他搜索引擎)索引的文章列表.
怎么用于找到给定文章的类似文章?
:如果这有重新恢复的工具,像做 http://www.wordsfinder.com/api_Keyword_Extractor.php,或termextract从http://developer.yahoo.com/yql/console,或HTTP://www.alchemyapi .com/api/demo.html?
关于该项目的一些细节:
纯后端项目,没有前端
暴露一个休息api(可能是自定义路由?)
连接到其他休息api
使用ORM查询MySQL和MongoDB
有单元测试
你会为我推荐什么样的Python框架?
ruby ×4
lucene ×3
solr ×3
mongodb ×2
python ×2
sunspot ×2
activerecord ×1
caching ×1
debian ×1
django ×1
download ×1
geocoding ×1
geolocation ×1
http ×1
models ×1
mongodb-ruby ×1
morelikethis ×1
named-scope ×1
nosql ×1
orm ×1
performance ×1
pylons ×1
sinatra ×1
sqlalchemy ×1
ubuntu ×1