Hi Techies,
I am working on Holy Quran. I have to sort the Chapters by Most Mentioned Words and Least Mentioned words.
I am using MySql as database and Quran Chapters are stored in table as paragraph.
I think I should count all the words in Quran using PHP. On the basis of that I can sort the Chapters.
Below is the code to extract the keywords from paragraph and stored in Keywords.
I think the below solution is lengthy one. I am not sure that using the above solution I can get the exact results. If there is any other solution please let me know.
public function insertKeywords(){
set_time_limit(0);
set_time_limit(3000000);
$allData = Quran::select('*')->paginate(1000);
foreach($allData as $data){
$newData = explode(" ",$data->AyahText);
foreach($newData as $keyWord){
# Check data already exist
$findWord = Keyword::select('*')->where('Keyword','=', $keyWord)->first();
if($findWord){
$count = $findWord->KeywordCount+1;
#Update
Keyword::where('ID','=',$findWord->ID)->update(['KeywordCount' => $count]);
}else{
$count = 1;
Keyword::insert([
'Keyword'=> $keyWord,
'VerseID' => $data->VerseID,
'SuraID' => $data->SuraID,
'AyahTextID' => $data->AyahTextID,
'LanguageID' => $data->LanguageId,
'KeywordCount' => $count
]);
}
}
}
}
via Chebli Mohamed
Aucun commentaire:
Enregistrer un commentaire