主题:  在director里面实现对文本的搜索

jiesun

职务:普通成员
等级:1
金币:1.0
发贴:182
#12001/5/12 22:03:56
我今天刚刚写了一段程序,实现对一个text cast member中的文本进行关键字搜索。没有使用xtra。
我采用的是逐行搜索,我的文本很大,存成txt文件,有600k。
平均的搜索时间在5秒以上,很慢,有没有更快的方法?

原程序如下:
property pSearchTextName
property pPathNum,pNameNum

on beginSprite me
  --要搜索文本的名字
  pSearchTextName = "Content"
  pPathNum = 1
  pNameNum = 1
end

on mouseUp me
  --searchWhat:用户输入的关键字
  searchWhat = member("input").text
  --跳转到搜索程序模块
  GoSearchNow(searchWhat)
end


--搜索程序模块
on GoSearchNow WhatSearch
  --开始计时
  startTimer
  --NumOfLine:目标搜索文本的行数
  NumOfLine = member(pSearchTextName).line.count
  --开始循环搜索
  repeat with i = 1 to NumOfLine
    TextOfCurrentLine = member(pSearchTextName).line[i]
    temp = offset(WhatSearch,TextOfCurrentLine)
    if temp > 0 then
      GetPath(i)
    end if
  end repeat
  TotalTime = the timer/60
  member("searchTime").line[2] = string(TotalTime) & " 秒"
end

on GetPath currentLine
  repeat with j = currentLine down to 1
    if member(pSearchTextName).line[j].char[1..3] = "z:\" then
      
      temp1 = member(pSearchTextName).line[j].char.count
      member("outputPath").line[pPathNum] = member(pSearchTextName).line[j].char[3..temp1]
      pPathNum = pPathNum + 1
      
      temp2 = member(pSearchTextName).line[j+1].char.count
      member("outputName").line[pNameNum] = member(pSearchTextName).line[j+1]
      pNameNum = pNameNum + 1
      
      exit repeat
    end if
  end repeat
end

编辑历史:[这消息被flyingbird编辑过(编辑时间2001-05-13 05:30:21)]


D计划-混沌

职务:管理员
等级:6
金币:15.2
发贴:3528
#22001/5/13 15:08:26
必须找到频率与计算量的结合点(有点类似蚂蚁的多线程思路)
offset并不是很优秀的比较,自己写算法肯定要快
据说mmx时代已有工具xtras比简单lingo搜索快四五倍。。。。
我以前的经理能在10秒内检索一个G的数据,所以他是经理,虽然他只会用FOXPRO
可惜我暂时还是没有时间和精力,不知道你有没有



zwjn

职务:普通成员
等级:1
金币:0.0
发贴:110
#32001/5/14 15:39:05
建议你先把文本文件分成几个段落来分别处理,原先我也是搜索一个几千K的文本足足搜了我半分多钟,后来分为几个小段(在程式里面分)没到2秒就搜索完了



jiesun

职务:普通成员
等级:1
金币:1.0
发贴:182
#42001/5/14 18:00:13
你的意思是我把那个text分成n段,然后分别检索吗,我想一定能够快了,这就试一下。



D计划-混沌

职务:管理员
等级:6
金币:15.2
发贴:3528
#52001/5/14 19:35:35
不是分别是同时