我正在开发一个Rails v2.3应用程序,该应用程序是a服务,用于搜索项目信息,项目信息储存在数据库中。
数据库现有<代码>项目代码>表如下:
For the sake of satisfying customer’s requirement, this table needs to insert new data in the mid-night everyday.
www.un.org/Depts/DGACM/index_spanish.htm 创建这些新记录的原因是,铁路申请除了用全称搜索外,还能够用一个字搜索项目。
www.un.org/Depts/DGACM/index_spanish.htm 例如,如果用“portal”一词搜索,则两者兼有。 铁路应用中应当找到汽车租赁门户和Position道门户记录。 <> 代码>项目名称代码>。
因此,我计划通过<>分配中的价值>生成这些新记录。 (上述<条码>项目代码>表>)改为“,然后将每一字作为 >,新纪录<条码>项目_代码>,同时保持其他栏目不变。
www.un.org/Depts/DGACM/index_spanish.htm 例如,上表上的第1个记录有 项目_ 姓名
“Car le Portal”,I gonna的意思是将这一座标分为3个字和,将以下3个新记录插入表格:
To achieve this. I tried to make a rake task which gets all records from the original projects
table, and for each record, the rake task splits the string value of project_name
column into words, then construct the new records with words and insert into the table. My rake task looks like the code below:
all_records = ActiveRecord::Base.execute("select * from projects;")
all_records.each do |record|
user_id = record[0]
project_name=record[1]
department = record[2]
other = record[3]
words=project_name.split()
words.each do |word|
sql = "insert into project values (#{user_id},#{word},#{department},#{other});"
ActiveRecord::Base.execute(sql)
end
end
The rake task works well, it creates the expected new records and inserted into the projects
table, BUT the problem is it takes 36 hours to complete!
之所以可以理解,是因为原表非常庞大,如果将插图与文字分开,并创造新记录,那么它就会产生3倍的较大表格(每个字面上>_name/code>有3字)。
www.un.org/Depts/DGACM/index_french.htm
Could some Rails experts suggest me some more efficient way to achieve the new record insertion thing I described above?
或者在我的案件中采用任何新的方法进行单独一字搜索? (没有使用我设计的将每一字储存在数据库中的方式。)