php 使用完全匹配关键字laravel FMKS排序排序

Posted

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了php 使用完全匹配关键字laravel FMKS排序排序相关的知识,希望对你有一定的参考价值。

        <!-- top rated widget -->
                    @if($iserp_data['best_keyword'] == 'y')
						@php $fkms_result = array(); $fkms_rating_sort_result = array(); $rating = array();
						@endphp
						{{-- if natural results exist --}}
						@if($iserp_data['search']['total']['natural'] > 0)
						{{-- fetch just the products that have keyword_matched =1 (FKMS product) and save it in array --}}
							@foreach($iserp_data['search']['natural']['results'] as $key=>$search_result) 
								@if(isset($search_result['keyword_matched']) && $search_result['keyword_matched'] == '1')
									@php
										$fkms_result[] = $search_result; 
									@endphp
								@endif 
                            @endforeach 


							{{-- if FKMS products are less than 4 under natural results then check under related/expanded results for FKMS products--}}
							@if(count($fkms_result) < 4) 
								@if($iserp_data['search'][ 'total'][ 'expanded']> 0) 
								{{-- fetch just the products that have keyword_matched =1 (FKMS product) and save it in array --}}
									@foreach($iserp_data['search']['expanded']['results'] as $key=>$search_result) 
										@if(isset($search_result['keyword_matched']) && $search_result['keyword_matched'] == '1')
											@php $fkms_result[] = $search_result; @endphp
										@endif 
									@endforeach
								@endif 
							@endif 
                            {{-- if natural results do not exist --}}
                            

						@elseif($iserp_data['search']['total']['natural'] == 0) 
						{{-- fetch just the products that have keyword_matched=1 (FKMS product) and save it in array --}} 
							@foreach($iserp_data['search']['expanded']['results'] as $key=>$search_result)
								@if(isset($search_result['keyword_matched']) && $search_result['keyword_matched'] == '1') 
									@php $fkms_result[] = $search_result; @endphp 
								@endif
							@endforeach 
                        @endif
                        
                        @if(count($fkms_result) >= 4) 

                        @php $total_number_of_results_with_reviews = 0; @endphp
						{{-- save the average_rating under reviews attribute of the FKMS products in a separate array to use it for sorting the array--}} 
                            @foreach($fkms_result as $key => $fkms_item)
								@php 
                                    $rating[$key] = $fkms_item['attributes']['reviewstars'];
                                    if(intval($fkms_item['attributes']['reviewstars']) > 0) {
                                        $total_number_of_results_with_reviews++;
                                    }
								@endphp
							@endforeach
							{{-- sort the FKMS products in descending order based on the average_ratings --}} 
                            @php
                             if($total_number_of_results_with_reviews > 2) {
                                array_multisort($rating,SORT_DESC, $fkms_result);
                            @endphp
                            @include('layouts.top-rated-widget')
                            @php
                            } 
							@endphp 
						@endif
                    @endif
                    <!-- end top rated widget -->

以上是关于php 使用完全匹配关键字laravel FMKS排序排序的主要内容,如果未能解决你的问题,请参考以下文章

如何使用 PHP Laravel 将输入字段与列数据库中的数据匹配?

Laravel(PHP)使用Swagger生成API文档不完全指南 - 基本概念和环境搭建 - 简书

升级 Laravel 5.6 的 Envoyer 部署失败引用不匹配的 PHP 版本

php精简完全小结(linux/laravel篇)

Dropzone CSRF令牌不匹配Laravel 5

php laravel php功能keywork在iserp中找到关键字