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.
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.
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!
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.
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?
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.
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…
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.
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.
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.
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!
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!
Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.