简体   繁体   中英

Return search results matching multiple query tags?

I'm using OctoberCMS based on Laravel.

I have an html search field which query string is parsed with php.

Laravel returns database results based on the url tag parameter using MySQL WHERE LIKE .

It works with 1 tag, but how to return results matching multiple tags separated by commas or spaces?

HTML5 Search Input

<form action="/search">
  <input type="search" name="tags" multiple>
  <button type="submit">search</button>
</form>

Single tag search

localhost/search?tags=galaxy

Multiple tag search

commas localhost/search?tags=galaxy%2C+stars%2C+universe
spaces localhost/search?tags=galaxy+stars+universe

This should return any tags matching in the database table's tags column.

The problem is that it sees the query as galaxy AND stars AND universe and not individual tags: galaxy , stars , universe .

Search Results

$query_string = $tags = '';

$query_string = getenv('QUERY_STRING');

// Return search results matching query string
return $query->where('tags', 'like', "%$tags%");

$query is part of OctoberCMS.

Example

结果

Problem

问题

Confusing,. Try logical OR to find value in table column may be it will help, if your finding it from webpages first fetch meta tags in function like google use keyword for search result

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM