Plugin

Archived
Forum
(read-only)

Search Fields

ExpressionEngine 1.x, ExpressionEngine 2

Back to this add-on's main page
View Other Add-ons From Mark Croxton

     

Getting no results when should be filtering results list

Support Request

brianrivet
brianrivet

Hi,

I’m setting up a page that defaults to listing all of the entries in a channel when you come to the page, but if you select some preset filters in a form on the page it should refresh with the results filtered. The form seems to be working and it is passing embed values to the page with the search results, but the results aren’t filtering. Here’s my code from the embed that displays the search results:

{embed:chamberSearch}
{exp
:search_fields 
    search
:legislator_chamber="{embed:chamberSearch}" 
    
search:legislator_party="{embed:partySearch}" 
    
search:legislator_district="{embed:districtSearch}"
    
operator="OR" 
    
channel="legislators" 
    
parse="inward"}

    
<div class="searchResults">
    <
h4>Showing All Legislators</h4>
    <
table class="table table-striped searchRes">
     <
thead>
      <
tr>
       <
th>Legislator</th>
       <
th>LABI Score</th>
      </
tr>
     </
thead>
     <
tbody>

    
{exp:channel:entries channel="legislators" entry_id="{search_results}" limit="200" orderby="legislator_last_name|legislator_first_name" sort="asc" dynamic="no"}

        
<tr>
<
td>
<
img src="{legislator_photo}" alt="{legislator_first_name} {legislator_middle_name} {legislator_last_name} {legislator_suffix}" class="legPhoto" />
<
class="legName"><a href="{page_url}">{if "{legislator_chamber}" == "Senate"}Senator{if:elseif "{legislator_chamber}" == "House of Representatives"}Representative{/if} {legislator_first_name} {legislator_middle_name} {legislator_last_name} {legislator_suffix}</a><br />District {exp:playa:children field="legislator_district"}{district_number}{/exp:playa:children}</p>
</
td>
<
td>{legislator_labi_score limit="1" orderby="score_date" sort="desc"}{score_number}%{/legislator_labi_score}</td>
</
tr>
        

    
{/exp:channel:entries}

</tbody>
</
table>    
</
div>

    
{if no_results}
 
<div class="searchResults">
        <
h4>Showing All Legislators</h4>
    <
table class="table table-striped searchRes">
     <
thead>
      <
tr>
       <
th>Legislator</th>
       <
th>LABI Score</th>
      </
tr>
     </
thead>
     <
tbody>

    
{exp:channel:entries channel="legislators" limit="200" orderby="legislator_last_name|legislator_first_name" sort="asc" dynamic="no"}

        
<tr>
<
td>
<
img src="{legislator_photo}" alt="{legislator_first_name} {legislator_middle_name} {legislator_last_name} {legislator_suffix}" class="legPhoto" />
<
class="legName"><a href="{page_url}">{if "{legislator_chamber}" == "Senate"}Senator{if:elseif "{legislator_chamber}" == "House of Representatives"}Representative{/if} {legislator_first_name} {legislator_middle_name} {legislator_last_name} {legislator_suffix}</a><br />District {exp:playa:children field="legislator_district"}{district_number}{/exp:playa:children}</p>
</
td>
<
td>{legislator_labi_score limit="1" orderby="score_date" sort="desc"}{score_number}%{/legislator_labi_score}</td>
</
tr>
        

    
{/exp:channel:entries}

</tbody>
</
table>    
</
div>

    
{/if}
{
/exp:search_fields} 

When I select a filter from the list in the form and submit, the page refreshes and I can see that the embed variables are being set, but the results are behaving as if there are no results. Can you see anything that might be causing this?

Thanks,

Brian

 

Mark Croxton
# 1
Developer
Mark Croxton

Not entirely sure, but I think you need to use AND as the operator so that your results are narrowed by the filters. Let me know how that works, if you still have problems turn on the Output Profiler in the admin and let me know what query is being generated by search_fields.

brianrivet
# 2
brianrivet

It tried switching to AND and it still isn’t returning results. I turned on the output profiler, but I’m not sure how to find which query is being generated by search_fields. Can you tell me how to find it?

brianrivet
# 3
brianrivet

I was able to get some results, but it isn’t behaving as I would expect. Do you know if spaces in a search term are a problem? I have removed all the search fields except one to try and see if I could get any searches to work at all. I’m running a search against the legislator_chamber field which has two possible values, “House of Representatives” and “Senate”. If I set the filter to Senate, it returns just the senators as expected, but if I set it to House of Representatives or both, it returns no results. I checked the spelling to make sure the filter wasn’t passing a bad search term, but it is spelled correctly. Any ideas?

brianrivet
# 4
brianrivet

I’m also getting some unexpected behavior when I use search syntax. In testing out the district search feature, the district list has the following list of possible values:

House District 1
Senate District 1
House District 2…

etc. The house districts go up to 105 and the senate to 39. When I select House District 1, I get a list of results that include any house district with the number 1 in the the number (House District 1, 10, 100, etc.)

If I try to add an = sign in front of the embed tag in the search parameter (search:legislator_district=”={embed:districtSearch}”), it returns no results instead of matching just House District 1.

brianrivet
# 5
brianrivet

I got the district part worked out. It was an issue with how playa fields store their data. I still need help with the issue where there are spaces in the value throwing it off.

brianrivet
# 6
brianrivet

I’ve definitely been able to narrow it down to an issue in search_fields with having spaces in the search term. If I put the search directly into the channel entries tag for House of Representatives it pulls the expected results, but if I remove it and just pass House of Representatives via search fields it returns no results. If you know of any other reason why this might be happening please let me know so I can resolve this issue.

Thanks,

Brian

Mark Croxton
# 7
Developer
Mark Croxton

Could be the same issue as here with stop words:
http://devot-ee.com/add-ons/support/search-fields/viewthread/5981

I’ll take a look next week and see if I can resolve it. As you appear to only be searching custom fields you could actually just use the channel module for this (although I think it has the same problem with stop words).

Mark Croxton
# 8
Developer
Mark Croxton

Regarding exact searches, see syntax here for the search param. This is for the channel module but applies to search_fields too:
http://expressionengine.com/user_guide/modules/channel/channel_entries.html#search-field-name