sql - full text search with multiple text input -


i'm trying full text search 2 text input fields.

 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); } 

however not work. tried storing both inputs array , did not work, works if use 1 input. best way around it? i'm using laravel 5.0. have looked solution across site have not found one.

my view form looks this:

{!! 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') !!} 

this route:

route::post( 'matchsearch',   array(  'as' => 'match.search',   'uses' => 'searchcontroller@searchmatch'     )  );   class productstable extends migration {  /**  * run 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 migrations.  *  * @return void  */ public function down() {     schema::table('products', function($table) {             $table->dropindex('search');         });     schema::drop('products'); }  } 

id:1
name: styletto
brand: lime crime
imagepath: img/2_lime-crime-lipstick-in-styletto.jpg price:$18.00 description: bold, opaque & recklessly loaded pigment. lips speak louder words! hex:#1b191b rgb:27,25,27 colour:black
link:http://www.limecrime.com/unicorn-lipstick/

updated: try

$products = db::table('products')     ->whereraw('match(hex,rgb) against(? in boolean mode)', array("$hex $rgb")                       ->get(); 

"$hex $rgb" - no fts operators means $hex or $rgb
"+$hex +rgb" - means $hex , $rgb

here sqlfiddle demo

further reading:


Comments

Popular posts from this blog

c# - Validate object ID from GET to POST -

node.js - Custom Model Validator SailsJS -

php - Find a regex to take part of Email -