私は脚本から短いラインの非常に巨大なjsonファイルを持っています。私はjsonファイル内のキーワードにキーワードを一致させようとしているので、jsonからの行を引き出すことができます。大規模なjsonでのルビーの検索
[
"Yeah, well I wasn't looking for a long term relationship. I was on TV. ",
"Ok, yeah, you guys got to put a negative spin on everything. ",
"No no I'm not ready, things are starting to happen. ",
"Ok, it's forgotten. ",
"Yeah, ok. ",
"Hey hey, whoa come on give me a hug... "
]
(合計に加えて、より多くの... 2444ライン)
は、これまでのところ、私はこれを持っているが、それはどんな試合をしていないです:
JSONファイル構造は次のようです。
# screenplay is read in from a json file
@screenplay_lines = JSON.parse(@jsonfile.read)
@text_to_find = ["relationship","negative","hug"]
@matching_results = []
@screenplay_lines.each do |line|
if line.match(Regexp.union(@text_to_find))
@matching_results << line
end
end
puts "found #{@matching_results.length} matches..."
puts @matching_results
私が働いていないものをそれほどわからない任意のヒットが届きません。さらに、大量のデータでこのように処理するのは非常に高価なプロセスだと私は確信しています。何か案は?ありがとう。
ありがとうございます。素晴らしい洞察find1()メソッドは正常に動作しています – matski