full text search with multiple text input

user3053151

I'm trying to do a full text search with two 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 it does not work. I tried storing both inputs into an array and it did not work, it only works if i use one input. What is the best way around it? I'm using Laravel 5.0. I have looked for a solution across the site also but I have not found one.

My view form looks like 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 is the route:

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
Name: Styletto
Brand: Lime Crime
Imagepath: img/2_lime-crime-lipstick-in-styletto.jpg Price:$18.00 Description: Bold, opaque & recklessly loaded with pigment. For lips that speak louder than words! HEX:#1B191B RGB:27,25,27 Colour:Black
Link:http://www.limecrime.com/unicorn-lipstick/

peterm

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 AND $rgb

Here is a SQLFiddle demo

Further reading:

이 기사는 인터넷에서 수집됩니다. 재 인쇄 할 때 출처를 알려주십시오.

침해가 발생한 경우 연락 주시기 바랍니다[email protected] 삭제

에서 수정
0

몇 마디 만하겠습니다

0리뷰
로그인참여 후 검토

관련 기사

분류에서Dev

Full text Search of browser history, through the browser

분류에서Dev

MySQL Full Text Search Returning 0 Results

분류에서Dev

MySQL Full Text Search "AND" BOOLEAN MODE to ElasticSearch

분류에서Dev

Full text search not giving desired result

분류에서Dev

MySQL full text search matching similar results

분류에서Dev

Data Table input type as text instead of search

분류에서Dev

GAE Full Text Search, querying multi-valued fields

분류에서Dev

Alfresco Full Text Search for JSON 텍스트 파일에서 쿼리 구성

분류에서Dev

C# Full-text search string format : string remove all adjacent duplicates and append with 'AND' 'OR'

분류에서Dev

Passing " as parameter in text search

분류에서Dev

MongoDB Text Search

분류에서Dev

Sublime Text Search and Insert

분류에서Dev

Search text From Arraylist

분류에서Dev

Text input and button alignment

분류에서Dev

Enabling text input

분류에서Dev

Text input value as a number

분류에서Dev

Advancing text in a text file using user input

분류에서Dev

Unary NOT operator in Oracle text search

분류에서Dev

Android white text in search box

분류에서Dev

How to search Sublime Text changelog?

분류에서Dev

Full text index on view with combined unique index

분류에서Dev

TextView doesn't show full text

분류에서Dev

Elasticsearch, filter on full-text string

분류에서Dev

HTML terminal like text input

분류에서Dev

Select all the text in an input, focusin

분류에서Dev

Firefox button and text input bug

분류에서Dev

Bold in the input causes weirdness text

분류에서Dev

PHP 'loop for' with input text form

분류에서Dev

regex for text box to validate input