Create a filter using two HubDB Text Columns

SOLVE
FredSan
Participant

Hi Developers,

I am building a page displaying cards and I want them to be filtered by "title" and "description". (both text columns in hubdb)

The search works fine when only searching by description, but as soon as I add the "title" search  things just won't work.

 

I have tried using this code: 

<!-- Search Input -->
<div class="search-input">
   <label for="description">Search By Title or Description</label>
   <div>
      <input name="description" type="text" id="search-by" class="autocomplete">
   </div>
</div>
<!-- Set Search Paramater -->
{% set queryparam = "" %}
  {% if request.query_dict.description != "" %}
    {% set queryparam = queryparam~"&description__icontains="~request.query_dict.title|urlencode~"&title__icontains="~request.query_dict.title|urlencode %}
  {% endif %}

<!-- Set Table and Queryparam -->
{% set table = hubdb_table_rows(XXXXXXX, queryparam) %}

  I have also tried creating two variables, descriptionquery and titlequery and joining the two search results with this attempt:

<!-- Set Search Paramater -->
{% set descriptionquery = "" %}
  {% if request.query_dict.description != "" %}
    {% set descriptionquery = descriptionquery~"&description__icontains="~request.query_dict.description|urlencode %}
  {% endif %}
  
{% set titlequery = "" %}
  {% if request.query_dict.description != "" %}
    {% set titlequery = titlequery~"&title__icontains="~request.query_dict.title|urlencode %}
  {% endif %} 

<!-- Set Table by Query -->
{% set table = hubdb_table_rows(XXXXXXX), descriptionquery + titlequery) %}

 Any help is greatly appreciated

0 Upvotes
1 Accepted solution

Accepted Solutions
FredSan
Solution
Participant

I have resolved the problem by combining the Title and Description into one Rich Text column and searching the single column.

View solution in original post

3 Replies 3
webdew
Top Contributor | Diamond Partner

Hi @FredSan ,
Please refer to the below solution.

Multi-select fields, in particular, return a list, where each selection is an object containing information like the ID of the selection and the name (the text of it).
So let's walk through some examples. Let's first assume that you have a multi select column named labeled ""Colors"" and whose name is ""colors"". Let's say it has selections of ""red"", ""green"", ""blue"".

<div class=""porfolio-services"">
<div class=""website box"" id=""portfolio_search"">
{% set table = hubdb_table_rows(111111, queryparam) %} {% if table == [] %}
{% else %}
{% for row in table %}

<div class=""categories-bx {{ row[""type""].name }}"">
<div class=""product-img"">
<img src=""{{ row[""IMAGE""].url}}"">
</div>
<div class=""categories-hover"">
<h5>{{ row.pname }}</h5>
<p>{{ row.description }}</p>
<a href=""{{ row.portfolio_url }}"" class=""btn-morinfo"">View Details</a></div>
</div>

{% endfor %}
{% endif %}
</div>

0 Upvotes
FredSan
Participant

Hi @webdew ,

Thank you for explaining the multi-select option for displaying a table.  The problem is that I have two "TEXT" columns in my hubdb, (Title and Description), and in my webpage I have only one search input box.

I am trying to find the query syntax to search both columns using just one search input box.

 

Does this make sense?

FredSan_0-1604094357126.png

 

0 Upvotes
FredSan
Solution
Participant

I have resolved the problem by combining the Title and Description into one Rich Text column and searching the single column.

View solution in original post