具有多个文本输入的全文搜索

时间:2015-06-13 19:38:23

标签: sql laravel input full-text-search laravel-5

我正在尝试使用两个文本输入字段进行全文搜索。

 public function searchmatch()
{
     $hex = Input::get('HEX');
     $rgb = Input::get('RGB')

        $products = DB::table('products')->whereRaw(
        "MATCH(HEX,RGB) AGAINST(? IN BOOLEAN MODE)", 
        array($hex,$rgb)
    )->get();


    return view('search')->with('products', $products);
}

然而它不起作用。我尝试将两个输入存储到一个数组中但它不起作用,它只有在我使用一个输入时才有效。围绕它的最佳方法是什么?我正在使用Laravel 5.0。我也在整个网站上寻找解决方案,但我还没找到。

我的观点表格如下:

{!! Form::model(null, array('route' => array('match.search'))) !!}
<ul>
<li><div id="hex">HEX:{!! Form::text('HEX') !!}</div></li>
<li><div id="rgb">RGB:{!! Form::text('RGB') !!}</div></li>
<li><div id="picked"></div></li>
<li>{!! Form::submit('Find Match', array('id' => 'submitbtn')) !!}</li>
</ul>
{!! Form::close('Search') !!}

这是路线:

Route::post(
'matchsearch', 
 array(
 'as' => 'match.search', 
 'uses' => 'SearchController@searchmatch'
    )
 );

 class ProductsTable extends Migration {

/**
 * Run the migrations.
 *
 * @return void
 */
public function up()
{
    Schema::create('products', function(Blueprint $table)
    {
        $table->increments('id');
        $table->engine = 'MyISAM';
        $table->string('name');
        $table->string('brand');
        $table->string('pathtoimage');
        $table->string('price');
        $table->text('description');
        $table->string('HEX');
        $table->string('RGB');
        $table->string('colour');
        $table->string('link');


    });
            DB::statement('ALTER TABLE products ADD FULLTEXT search(name,   brand,HEX,RGB,colour)');
}

/**
 * Reverse the migrations.
 *
 * @return void
 */
public function down()
{
    Schema::table('products', function($table) {
            $table->dropIndex('search');
        });
    Schema::drop('products');
}

}

ID:1个
名称:Styletto
品牌:Lime Crime
Imagepath:img / 2_lime-crime-lipstick-in-styletto.jpg 价格:$ 18.00 描述:大胆,不透明&amp;鲁莽地装载颜料。对于言语更响亮的嘴唇! HEX:#1B191B RGB:27,25,27 颜色:黑色
链接:http://www.limecrime.com/unicorn-lipstick/

1 个答案:

答案 0 :(得分:0)

更新:尝试

$products = DB::table('products')
    ->whereRaw('MATCH(HEX,RGB) AGAINST(? IN BOOLEAN MODE)', array("$hex $rgb")                  
    ->get();

"$hex $rgb" - 没有FTS运营商意味着$hex OR $rgb
"+$hex +rgb" - 表示$hex AND $rgb

这是 SQLFiddle 演示

进一步阅读: