We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Plugin: Search Fields

Development and Programming

ASC's avatar
ASC
21 posts
16 years ago
ASC's avatar ASC

Hi Mark, this is great.

I was wondering if there’s a way to get pagination to work with dynamically passed parameters.

Similar to somewhere above, I have

<?php
$keywords = str_replace(array('{','}','?','\"','\\'), '', trim($q = $IN->GBL('keywords', 'POST')));
?>
{exp:search_fields search:title="<?=$keywords?>" weblog="ijpc_db" operator="AND" parse="inward"}
    {exp:weblog:entries entry_id="{search_results}" dynamic="off" limit="10"}

        <a href="http://{page_url}">{title}</a>


{if paginate}
{paginate}
Page {current_page} of {total_pages} pages {pagination_links}
{/paginate}
{/if}

    {/exp:weblog:entries}
{/exp:search_fields}

The pagination links are meaningless because the ‘keywords’ POST variable does not exist once you click a link [Edit: which is to say, exp:weblog:entries will not return any results.]. Any ideas? Outside of writing {search_results} to a session variable, which might work, I’m not sure what to do here.

       
ASC's avatar
ASC
21 posts
16 years ago
ASC's avatar ASC

Another thing, is there any way for it to parse multiple search terms? The relevant part of your SQL I’m talking about comes out something like ( wt.title LIKE “%term1 term2%” ) . That might be called exact phrase matching. I think I’m looking for more like ( wt.title LIKE “%term1%” OR wt.title LIKE “%term2%” ) .

I guess in general, as feature request unless it’s in there but I’m missing it, I’m looking for support like the where option offers in the Adavanced Search Form.

       
teagirl's avatar
teagirl
17 posts
about 16 years ago
teagirl's avatar teagirl

Hi, Will the EE 2.0 version be out any time soon? Thanks!

       
Frank Harrison's avatar
Frank Harrison
154 posts
15 years ago
Frank Harrison's avatar Frank Harrison

Am having trouble with a site running out of memory, on a page that uses search_fields. I’m getting this error:

Fatal error: Allowed memory size of 33554432 bytes exhausted (tried to allocate 806656 bytes) in /var/www/vhosts/sitename.com/httpdocs/system/db/db.mysql.php on line 405

The code on that page is a little complex, but I’m surprised that 32MB of RAM isn’t enough. Here’s what I’m guessing is causing it to run out of memory (this is the most complex bit of the template)…

{exp:search_fields search:title="<?php echo $keywords ?>" parse="inward"}
    {exp:weblog:entries weblog="my-weblog" entry_id="{search_results}" dynamic="off" paginate="top" limit="10" orderby="title" sort="asc" category="<?php echo $categories ?>"}
        <!-- DO STUFF HERE WITH THE RETURNED ENTRIES ...  -->
        {paginate}
            {if "{total_pages}" != 1}{pagination_links}{/if}
        {/paginate}
    {/exp:weblog:entries}
{/exp:search_fields}

So, the keywords/categories are added in via PHP (they’re submitted by a form), and I’m Search Fields to search the titles first, then a normal entries tag to filter by category. The page crashes when $keywords==”” and $categories==”” (so it’s returning all results). It was working though until recently - don’t know if it’s because the client has added more entries.

Any ideas why this might be using so much memory? Obviously, I could just up the memory limit, but I feel like I should fix the problem rather than patch it…

P.S am posting this in “How to” as well as here - apologies for the double posting but wasn’t sure where was the best place for this, and need to find a fix asap!

       
ASC's avatar
ASC
21 posts
15 years ago
ASC's avatar ASC

I noticed it was using a query in the form SELECT * from T WHERE entry_id IN (1,2,3 … n) . In my case the IN list was thousands of records long (my weblog had 75,000 entries), and so PHP couldn’t handle that. I’m not sure if it was the size of the query, or the result set. I doubled or quadrupled the memory limit and still had the problem. In the end I scrapped using the plugin and just wrote my own PHP and SQL (using subqueries and/or temp tables to achieve a similar approach to using IN); it got a little complicated but I found the custom solution worked better for me. I think it depends on your case.

       
Frank Harrison's avatar
Frank Harrison
154 posts
15 years ago
Frank Harrison's avatar Frank Harrison

Thanks for your reply. The site I’m working on has only around 500 entries in that weblog, which shouldn’t be too big a deal. The fact that it was working and now doesn’t suggests to me that it’s the increase in entries that has caused it, but I would have thought that searching 500 entries in this way (or even 1000) shouldn’t cause it to crash. I don’t know if this makes a difference, but I have a similar query just before it in the same page (I had to do 2 separate calls to display total number of results, then the paginated results). Any ideas?

       
Orange Tree Ln's avatar
Orange Tree Ln
3 posts
15 years ago
Orange Tree Ln's avatar Orange Tree Ln

Awesome, thanks so much.

<major_rant> I just figured out today that ee’s built in search functions are <rant>woefully, fearfully</rant> lame. I am building my first ee based site, and I had put off until now figuring out the search functionality. When I realized that the weblog module doesn’t allow easy searching by title I was amazed. When I further realized that the integration of weblog module with the search module is a <rant>woeful, klunky</rant> mess I was dumbfounded. How is it that a content management system with as much going for it as ee has a flaw of this size right at the center?</major_rant>

Anyway, after staring at the problem for about an hour I figured I was going to have to write some custom code for handling standard searches. Then I had the bright idea of looking here on the message boards, and wallah! Took me about 15 minutes to get it functional and another half hour to get it configured.

I am truly amazed that EE doesn’t come with this functionality out of the box. I am further amazed that more people aren’t screaming about it.

       
Frank Harrison's avatar
Frank Harrison
154 posts
15 years ago
Frank Harrison's avatar Frank Harrison

Hi All. Sorry to re-post, but any thoughts as to my last two posts (above)? My site is still running out of memory whenever someone searches with either no keywords for the Title field, or very short ones (like “a”). I’m concerned that this is because it’s choking on the 500+ results returned, and that as the site grows, I’m going to be getting 500+ results for longer keyword searches. (I could add some code to force people to search for at least 3 characters, say, but that won’t help if this is the case.)

Love this plugin - it’s made some very cool stuff possible on my site - but need to fix this or find another way to do it…

       
struiling's avatar
struiling
10 posts
15 years ago
struiling's avatar struiling

Modification to the plugin, specifically Brian’s multiple weblog code:

// limit to a weblog?
        if ($weblog !== '*')
        {
            // Added by Brian Litzinger
            if(substr($delimiter, $weblog))
            {
                $weblogs = explode($delimiter, $weblog);
                $sql_conditions = "(".$sql_conditions.") AND (";
                foreach($weblogs as $wb)
                {
                    $sql_conditions .= "wl.blog_name = '{$DB->escape_str($wb)}' OR ";
                }
                $sql_conditions = substr($sql_conditions, 0, -4);
                $sql_conditions .= ")";
            }
            else
            {
                $sql_conditions = "(".$sql_conditions.") AND wl.blog_name = '{$DB->escape_str($weblog)}'";
            }
        }

Added parentheses around $sql_conditions before the weblog specifications. Otherwise with the OR operator, results were coming from all weblogs, not just the one I specified.

Separately, the default operator is actually AND, not OR.

       
Tyssen's avatar
Tyssen
756 posts
15 years ago
Tyssen's avatar Tyssen
Alternatively you can use the dynamic_parameters parameter to tell the script to grab the submitted values from the $_POST array, although you would need to duplicate the field values if you’re searching in more than one custom field for the same string.

I don’t really understand how the dynamic_parameters parameter is supposed to work. Anyone have an example they could show me?

I’m also having trouble with returning a message if no results are returned. My template looks like this so far:

{exp:search_fields weblog="weblog" search:suburb="<?php echo $_POST['suburb'] ?>" search:pcode="<?php echo $_POST['pcode'] ?>" operator="OR" parse="inward"}

        <table>
            <thead>
                <tr>
                    <th scope="col">Name</th>
                    <th scope="col">Address</th>
                </tr>
            </thead>
            <tbody>
            {exp:weblog:entries entry_id="{search_results}" dynamic="off"}

                <tr class="{switch="one|two"}">
                    <th class="left" scope="row">{title}</th>
                    <td class="left">{address}</td>
                </tr>
            {/exp:weblog:entries}
            
            </tbody>        
        </table>

        {/exp:search_fields}

I thought I could use a conditional on {if search_results == ""}, say there are no results, but whenever I do, the result is to always show the no results message, even when entering a query which should show results.

       
heaversm's avatar
heaversm
197 posts
15 years ago
heaversm's avatar heaversm

Hi - EE doesn’t natively allow you to search titles, so I thought your plugin might do the trick. However, I am currently using dynamic parameters. Does your plugin support that? If so, how would that work. This is my current setup:

{exp:weblog:entries weblog="publications" dynamic_parameters="search:pub_date|search:title|search:pub_issue|search:pub_type" limit="10" paginate="bottom"}

Where the dynamic parameters are passed from a previous form. Everything works except search:title, because it returns all results.

       
djfenske's avatar
djfenske
17 posts
15 years ago
djfenske's avatar djfenske

I’m also having a hard time getting the dynamic_parameters to work. Am I missing something obvious?

Form Code:

<form action="{path='find/by-company-name'}" method="post">
<input type="text" name="title" id="title" /><br >
<input type="submit" value="Go!" />
</form>

Search Fields tags from find/by-company-name:

{exp:search_fields weblog="supplier-profile" dynamic_parameters="title" parse="inward"}
{exp:weblog:entries weblog="supplier-profile" entry_id="{search_results}" dynamic="off" orderby="title" sort="asc"}
    <tr>
    <td><a href="http://{url_title_path=profiles/display}">{title}</a></td>
    <td>{displayed-city}</td>
    <td>{displayed-state}</td>
    </tr>
{/exp:weblog:entries}
{/exp:search_fields}

The plugin worked great with search term hard coded. Just can’t get the dynamic_parameters to pick it up!

Thanks so much for your help!

       
benjivm's avatar
benjivm
5 posts
11 years ago
benjivm's avatar benjivm

This plugin looks like it does what I want, but it isn’t behaving as expected. I am attempting something really simple: search two custom fields and if either of them is populated, return results:

{exp:channel:entries channel="machines" sort="desc" status="open" search:machine_parts_catalog="not IS_EMPTY" operator="OR" search:machine_manual="not IS_EMPTY"}

But EE returns results as if the operator=”OR” is not there: it only returns results where both fields are populated, rather than either.

Figured it out, turns out I wasn’t using the search_field tag, oops! Here’s my functional code:

{exp:search_fields 
 search:machine_parts_catalog="not IS_EMPTY"
 search:machine_manual="not IS_EMPTY"
 operator="OR" 
 channel="machines"
 parse="inward"}
{exp:channel:entries entry_id="{search_results}" sort="desc" status="open"}

Awesome!

       
giant2015's avatar
giant2015
3 posts
8 years ago
giant2015's avatar giant2015

Hi, anyone know how to download EE 1 version.

I use wayback saw old forum have File Attachments pi.search_fields.zip (File Size: 4KB - Downloads: 304)

but in this new forum can’t find the attachment file.

Thanks.

       
smartpill's avatar
smartpill
456 posts
8 years ago
smartpill's avatar smartpill

Hi giant2015, I have a copy of the EE1 version. Just let me know how to get it to you.

       
1 2 3 4

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.