I'm completely "zero" in angularJS and need to improve the search functionality on this link site that was not developed by me.
At this point the search is "stuck" to the list of features that hang over the search box, not allowing a free search.
Search Code
public function querySearch()
{
$query = Product::selectAll()->groupBy('products.id');
if (Input::get('purpose'))
{
$purpose_id = Input::get('purpose');
$query->join('product_purpose', function($join) use($purpose_id)
{
$join->on('product_purpose.product_id', '=', 'products.id')
->where('purpose_id', '=', $purpose_id);
});
}
if (Input::get('category'))
{
$query->where('category_id', Input::get('category'));
}
$available_filters = array_keys(Product::allFilters());
foreach ($available_filters as $filter)
{
if (Input::has($filter))
{
switch ($filter)
{
case 'color' :
$colors = explode(',', Input::get('color'));
foreach ($colors as $i => $color)
{
$alias = "color_product_$i";
$query->join("color_product as $alias", function($join) use($color, $alias)
{
$join->on("$alias.product_id", '=', 'products.id')
->where("$alias.color_id", '=', $color);
});
}
break;
case 'pattern' :
$patterns = explode(',', Input::get('pattern'));
foreach ($patterns as $i => $pattern)
{
$alias = "pattern_product_$i";
$query->join("pattern_product as $alias", function($join) use($pattern, $alias)
{
$join->on("$alias.product_id", '=', 'products.id')
->where("$alias.pattern_id", '=', $pattern);
});
}
break;
case 'width' :
$widths = array_map(function($width)
{
return (string)bcdiv($width, 100, 2);
}, explode(',', Input::get('width')));
$first_width = array_shift($widths);
$query->where(function($query) use($first_width, $widths)
{
$query->where('dimension_x', $first_width);
foreach ($widths as $width)
{
$query->orWhere('dimension_x', $width);
}
});
break;
case 'attribute' :
$attributes = explode(',', Input::get('attribute'));
foreach ($attributes as $i => $attribute)
{
$alias = "attribute_product_$i";
$query->join("attribute_product as $alias", function($join) use($attribute, $alias)
{
$join->on("$alias.product_id", '=', 'products.id')
->where("$alias.attribute_id", '=', $attribute);
});
}
break;
case 'keyword' :
$keywords = explode(',', Input::get('keyword'));
foreach ($keywords as $i => $keyword)
{
$alias = "keyword_product_$i";
$query->join("keyword_product as $alias", function($join) use($keyword, $alias)
{
$join->on("$alias.product_id", '=', 'products.id')
->where("$alias.keyword_id", '=', $keyword);
});
}
break;
case 'name' :
$names = explode(',', Input::get('name'));
$first_name = array_shift($names);
$query->where(function($query) use($first_name, $names)
{
$query->where('name', $first_name);
foreach ($names as $name)
{
$query->orWhere('name', $name);
}
});
break;
case 'ref' :
$refs = explode(',', Input::get('ref'));
$first_ref = array_shift($refs);
$query->where(function($query) use($first_ref, $refs)
{
$query->where('ref', $first_ref);
foreach ($refs as $ref)
{
$query->orWhere('ref', $ref);
}
});
break;
}
}
}
// Price filter
if (Input::has('min'))
{
$query->where('price_in_cents', '>=', Input::get('min')*100);
}
if (Input::has('max'))
{
$query->where('price_in_cents', '<=', Input::get('max')*100);
}
if (Input::get('sales'))
{
$query->whereOnSale();
}
$items = $query->where('active', true)
->orderBy('updated_on_remote', 'desc')
->orderBy('ref', 'asc')
->paginate(Input::get('limit'));
$items->setBaseUrl(url(Input::get('base_url')));
return $items;
}
public function search()
{
$items = $this->querySearch();
Session::put('limit.search', Input::get('limit', 24));
return View::make('partials.search-results', compact('items'));
}
I want to change the search to be fulltext search, since at the moment I have a field in the products table with all the words that really matter that are searchable.