<legend id='T7qTo'><style id='T7qTo'><dir id='T7qTo'><q id='T7qTo'></q></dir></style></legend>
        <i id='T7qTo'><tr id='T7qTo'><dt id='T7qTo'><q id='T7qTo'><span id='T7qTo'><b id='T7qTo'><form id='T7qTo'><ins id='T7qTo'></ins><ul id='T7qTo'></ul><sub id='T7qTo'></sub></form><legend id='T7qTo'></legend><bdo id='T7qTo'><pre id='T7qTo'><center id='T7qTo'></center></pre></bdo></b><th id='T7qTo'></th></span></q></dt></tr></i><div id='T7qTo'><tfoot id='T7qTo'></tfoot><dl id='T7qTo'><fieldset id='T7qTo'></fieldset></dl></div>

        <small id='T7qTo'></small><noframes id='T7qTo'>

      1. <tfoot id='T7qTo'></tfoot>
          <bdo id='T7qTo'></bdo><ul id='T7qTo'></ul>

        Laravel 中的原始相关性查询.如何处理?

        时间:2023-09-22

            <bdo id='vFraT'></bdo><ul id='vFraT'></ul>
              <tbody id='vFraT'></tbody>
          • <legend id='vFraT'><style id='vFraT'><dir id='vFraT'><q id='vFraT'></q></dir></style></legend>
          • <i id='vFraT'><tr id='vFraT'><dt id='vFraT'><q id='vFraT'><span id='vFraT'><b id='vFraT'><form id='vFraT'><ins id='vFraT'></ins><ul id='vFraT'></ul><sub id='vFraT'></sub></form><legend id='vFraT'></legend><bdo id='vFraT'><pre id='vFraT'><center id='vFraT'></center></pre></bdo></b><th id='vFraT'></th></span></q></dt></tr></i><div id='vFraT'><tfoot id='vFraT'></tfoot><dl id='vFraT'><fieldset id='vFraT'></fieldset></dl></div>

            <small id='vFraT'></small><noframes id='vFraT'>

                <tfoot id='vFraT'></tfoot>

                1. 本文介绍了Laravel 中的原始相关性查询.如何处理?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                  问题描述

                  我目前正在将一个大项目转移到 Laravel 框架 http://hobbyathletes.com/events/south-america/all-event-types/all/.我需要迁移我的内部搜索引擎,它使用以下查询(如果搜索一个词,这里有额外的预选选项南美洲):

                  I'm currently transfering a big project to Laravel framework http://hobbyathletes.com/events/south-america/all-event-types/all/. I need to migrate my internal searchengine, which uses the following query (if searched for one word, here additional pre-selected option South America ):

                  SELECT *, (
                   (CASE WHEN name LIKE '%searchthis%' THEN 1000 ELSE 0 END) + 
                   (CASE WHEN name LIKE 'searchthis %' THEN 10 ELSE 0 END) + 
                   (CASE WHEN name LIKE 'searchthis%' THEN 1 ELSE 0 END) + 
                   (CASE WHEN name LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN city LIKE '%searchthis%' THEN 500 ELSE 0 END) + 
                   (CASE WHEN city LIKE 'searchthis%' THEN 10 ELSE 0 END) + 
                   (CASE WHEN city LIKE 'searchthis %' THEN 1 ELSE 0 END) + 
                   (CASE WHEN city LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN country LIKE '%searchthis%' THEN 500 ELSE 0 END) + 
                   (CASE WHEN country LIKE 'searchthis%' THEN 10 ELSE 0 END) + 
                   (CASE WHEN country LIKE 'searchthis %' THEN 1 ELSE 0 END) + 
                   (CASE WHEN country LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN homepage LIKE '%searchthis%' THEN 600 ELSE 0 END) + 
                   (CASE WHEN headline LIKE '%searchthis%' THEN 100 ELSE 0 END) + 
                   (CASE WHEN headline LIKE 'searchthis%' THEN 10 ELSE 0 END) + 
                   (CASE WHEN headline LIKE 'searchthis %' THEN 1 ELSE 0 END) + 
                   (CASE WHEN headline LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN description LIKE '%searchthis%' THEN 100 ELSE 0 END) + 
                   (CASE WHEN description LIKE 'searchthis%' THEN 10 ELSE 0 END) + 
                   (CASE WHEN description LIKE 'searchthis %' THEN 1 ELSE 0 END) + 
                   (CASE WHEN description LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN distances LIKE '%searchthis%' THEN 100 ELSE 0 END) + 
                   (CASE WHEN distances LIKE 'searchthis%' THEN 10 ELSE 0 END) + 
                   (CASE WHEN distances LIKE 'searchthis %' THEN 1 ELSE 0 END) + 
                   (CASE WHEN distances LIKE '% searchthis %' THEN 5 ELSE 0 END) + 
                   (CASE WHEN date LIKE '%2014%' THEN 300 ELSE 0 END) + 
                   (CASE WHEN name LIKE '%2014%' THEN 200 ELSE 0 END) + 
                   (CASE WHEN date LIKE '%2013%' THEN 200 ELSE 0 END) + 
                   (CASE WHEN name LIKE '%2013%' THEN 100 ELSE 0 END) 
                  ) 
                   AS relevance 
                   FROM events 
                   WHERE 
                   (
                   country = 'Argentina' or 
                   country = 'Bolivia' or 
                   country = 'Brazil' or 
                   country = 'Chile' or 
                   country = 'Colombia' or 
                   country = 'Ecuador' or 
                   country = 'Guyana' or 
                   country = 'Paraguay' or 
                   country = 'Peru' or 
                   country = 'Suriname' or 
                   country = 'Uganda' or 
                   country = 'Uruguay' or 
                   country = 'Venezuela'
                   ) 
                   AND
                   ( 
                   name LIKE '%searchthis%' OR 
                   country LIKE '%searchthis%' OR 
                   city LIKE '%searchthis%' OR 
                   homepage LIKE '%searchthis%' OR 
                   headline LIKE '%searchthis%' OR 
                   description LIKE '%searchthis%' OR 
                   distances LIKE '%searchthis%'
                  ) 
                  ORDER BY relevance DESC
                  

                  如何将此查询转移到 Eloquent Query builder?我已经尝试过 DB:raw($query) 这似乎不起作用......尝试使用的是非常需要的 ->paginate(25)->get(),都不起作用.这里的任何人都可以让我朝着正确的方向前进吗?

                  How can I transfer this query to Eloquent Query builder? I tried already DB:raw($query) which seems not to work... Tried is with the much needed ->paginate(25) and with ->get(), all not working. Anyone here can put me in the right direction?

                  推荐答案

                  Try with DB::select()

                  Try with DB::select()

                  DB::select(DB::raw("
                      SELECT * FROM bla bla bla  
                  "));
                  

                  这篇关于Laravel 中的原始相关性查询.如何处理?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                  上一篇:Laravel 块和删除 下一篇:Laravel:让 Eloquent 创建嵌套 SELECT 的正确方法

                  相关文章

                  最新文章

                    <i id='JscNV'><tr id='JscNV'><dt id='JscNV'><q id='JscNV'><span id='JscNV'><b id='JscNV'><form id='JscNV'><ins id='JscNV'></ins><ul id='JscNV'></ul><sub id='JscNV'></sub></form><legend id='JscNV'></legend><bdo id='JscNV'><pre id='JscNV'><center id='JscNV'></center></pre></bdo></b><th id='JscNV'></th></span></q></dt></tr></i><div id='JscNV'><tfoot id='JscNV'></tfoot><dl id='JscNV'><fieldset id='JscNV'></fieldset></dl></div>
                    • <bdo id='JscNV'></bdo><ul id='JscNV'></ul>

                    <small id='JscNV'></small><noframes id='JscNV'>

                    <legend id='JscNV'><style id='JscNV'><dir id='JscNV'><q id='JscNV'></q></dir></style></legend>

                    1. <tfoot id='JscNV'></tfoot>