2 of 3
2
Plugin: Search Fields
Posted: 26 January 2010 04:52 PM   [ Ignore ]   [ # 19 ]  
Lab Assistant
RankRank
Total Posts:  191
Joined  02-23-2009

I’ve been trying to use this with the {if no_results}{/if} tag, but can’t seem to get it to work - I’ve tried putting the no_results tag in the search_fields tags, and in the weblog tags, but neither seems to return a result.

Is there a way to get that to work, or is it not compatible with no_results?

Profile
 
 
Posted: 15 February 2010 01:35 PM   [ Ignore ]   [ # 20 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  258
Joined  10-08-2002

@SierraBravo
That’s great, thank you! I’ll add it to the next version.

@Frank Harrison
no_results will work, but will get overwritten if exp:search_fields is wrapped by another tag. Try using an embedded template for the tag, and inside that embed the exp:weblog tag.

Eg, {embed=“inc/search_fields” search_words=“my search word”}

{exp:search_fields search:title="{embed:search_words}" search:cat_name="{embed:search_words}" search:tags="{embed:search_words}" operator="OR" weblog="products" parse="inward"}
    {embed
="inc/product-search-results" search_results="{search_results}" categories="{embed:categories}"}
    {if no_results}
        Sorry
no matches were found for &lsquo;<em>{embed:search_words}&rsquo;</em>.
    
{/if}
{
/exp:search_fields} 
Profile
 
 
Posted: 19 February 2010 07:35 PM   [ Ignore ]   [ # 21 ]  
Research Assistant
Avatar
RankRankRank
Total Posts:  526
Joined  09-06-2006

This looks very useful. I added SierraBravo’s multiweblog code and it gets me closer to what I’m trying to accomplish but I still have an issue. I have multiple weblogs that I’m trying to pull entries from as I’ve detailed in this thread.

What I have so far is:

{exp:search_fields search:ee_body="not IS_EMPTY" search:body="not IS_EMPTY" operator="OR" 
weblog="nh_ee|nh_main|nh_obits" parse="inward"}
    {exp
:weblog:entries entry_id="{search_results}" dynamic="off" limit="25"<a href="{page_url}">{title}</a>
    
{/exp:weblog:entries}
{
/exp:search_fields} 

which is close but I’m getting results even when “body” field is empty.

This is a query someone else wrote that does what I want:

{exp:query sql="select d.entry_id 
from exp_weblog_data d inner join exp_weblog_titles t on d.entry_id=t.entry_id where d.weblog_id in 
('10','11','12') and (ASCII(d.field_id_50) > 0 OR ASCII(d.field_id_55) > 0) And t.status='open' order by 
t.entry_date desc LIMIT 0,26;" 
backspace="1"}{entry_id}|{/exp:query} 

but I was hoping to simplify it using a plugin. Is this beyond what you intended for this?

 Signature 

Kyle Summer | smartpill design | New Haven, CT |  twitter

Profile
 
 
Posted: 21 February 2010 07:41 PM   [ Ignore ]   [ # 22 ]  
Lab Assistant
RankRank
Total Posts:  218
Joined  07-16-2008

Are you making a version for EE 2.0 ?

Profile
 
 
Posted: 22 February 2010 09:16 AM   [ Ignore ]   [ # 23 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  258
Joined  10-08-2002

@smartpill
Hmm, tricky one. I can’t think of a way to do it easily, so I think your best bet is the query wrapped around exp:weblog:entries.

@11Media
Yes, but most likely not for a few months yet.

Profile
 
 
Posted: 02 March 2010 07:23 AM   [ Ignore ]   [ # 24 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  231
Joined  08-14-2007

Hey Mark

This is a great plugin and is currently working well for me. However, I’m just wondering whether you can advise me as to how I might do the following:

I’d like to pull out entries that ‘contain’ what’s in my search:title parameter, limit them to 500 and if there are less than 500 results, output whatever’s left (up to the 500 limit) with search:title=“title4”. Is that possible?

My current code which works great is:

{exp:search_fields search:title="title1|title2|title3" weblog="my_weblog" parse="inward"}
 {exp
:weblog:entries entry_id="{search_results}" weblog="my_weblog" dynamic="off" limit="500"}
  Output here
 {
/exp:weblog:entries}
{
/exp:search_fields} 

Many thanks,

 

Jim

 Signature 

Jim Pannell | Six Media Web Development | Copenhagen, Denmark
Twitter: @jimpannell

Profile
 
 
Posted: 03 March 2010 06:22 AM   [ Ignore ]   [ # 25 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  258
Joined  10-08-2002

Hi Jim

I think you could go about this two ways.

You could search for all 4 titles, set a limit of 500, and use a conditional within the exp:weblog:entries loop to attach a css class to rows where the entry title matches ‘title 4’; then use jquery (or your library of choice) to select these rows, remove them from their positions within the list, and bolt back on to the end of the list.

If you didn’t want to rely on client side javascript, I think your best approach (and the one I would take) would be to write a small plugin to do the same thing in PHP. This is how you could do it:

* add ‘title4’ to your search paramater.
* uncomment line 259 in pi.search_fields.php (echo $sql)
* look at the your page in a browser; you should see the sql output at the top of the screen - copy it.
* create a plugin that runs this query; iterate through the result set and create two arrays: array A would contain entires that match title1|title2|title3 and array B would contain title4 entries.
* concatenate array B onto array A (+ is the array concatenation operator)
* loop through the combined array extracting the entry ids and creating a pipe separated string of ids. Replace into your template (look at my plugin to see how I did this).
* wrap your custom plugin around exp:weblog:entries and set parse=“inward”.

Hope that makes sense smile

Profile
 
 
Posted: 03 March 2010 06:37 AM   [ Ignore ]   [ # 26 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  231
Joined  08-14-2007

This second approach would definitely work better - especially as it’s an xml feed! grin

I’d be interested to know how much you’d charge to write this plugin for me - please PM me if you’re interested.

Cheers


Jim

 Signature 

Jim Pannell | Six Media Web Development | Copenhagen, Denmark
Twitter: @jimpannell

Profile
 
 
Posted: 09 March 2010 09:04 AM   [ Ignore ]   [ # 27 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  03-21-2007

Hi Mark,

Great plugin. Thanks for sharing it. Could you please give me some pointers as to how to use this plugin in conjunction with the simple or advanced EE search forms?

Thanks

Profile
 
 
Posted: 09 March 2010 09:32 AM   [ Ignore ]   [ # 28 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  258
Joined  10-08-2002

Hi Bluebloc

think of it as a way to filter entries in very specific ways using the exp:weblog:entries tag, rather than as a replacement or enhancement of the search module. Take a look at my site here:
http://dev.lefroybrooks.com/ notab,ly the product section.

All of the ‘searching’, form filtering, tagging, the live search etc make use of the plugin in one way or another.

Profile
 
 
Posted: 09 March 2010 10:55 AM   [ Ignore ]   [ # 29 ]  
Lab Assistant
Avatar
RankRank
Total Posts:  162
Joined  03-21-2007

Hi Mark,

Thanks for posting that link. The question I had was really to do with passing the search_words input to the search results template. On your site you are using the following code:

<form id="livesearch" action="/products/search/" method="post">
<
label for="livesearch_words" accesskey="2">
<
input id="livesearch_words" name="search_words" type="text" value="" title="Product search..." />
<
button type="submit">Go</button>
</
label>
</
form

I assume that the input named “search_words” is passed to your products/search results template. Are the results generated using code similar to the below?

{exp:search_fields search:title="{embed:search_words}" search:cat_name="{embed:search_words}" search:tags="{embed:search_words}" operator="OR" weblog="products" parse="inward"}

{exp
:weblog:entries entry_id="{search_results}" dynamic="off"}
<a href="{page_url}">{title}</a>
{/exp:weblog:entries}

{
/exp:search_fields} 

Or do I need to post the “search_words” in another way?

Thanks again.

Profile
 
 
Posted: 31 March 2010 01:47 PM   [ Ignore ]   [ # 30 ]  
Grad Student
Rank
Total Posts:  35
Joined  03-03-2004

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="{page_url}">{title}</a><br>

{if paginate}
{paginate}
<p>Page {current_page} of {total_pages} pages {pagination_links}</p>
{/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.

Profile
 
 
Posted: 31 March 2010 02:49 PM   [ Ignore ]   [ # 31 ]  
Grad Student
Rank
Total Posts:  35
Joined  03-03-2004

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.

Profile
 
 
Posted: 17 April 2010 10:52 PM   [ Ignore ]   [ # 32 ]  
Summer Student
Avatar
Total Posts:  26
Joined  06-11-2007

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

Profile
 
 
Posted: 14 May 2010 07:10 AM   [ Ignore ]   [ # 33 ]  
Lab Assistant
RankRank
Total Posts:  191
Joined  02-23-2009

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}<class="pagination">{pagination_links}</p>{/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!

Profile
 
 
Posted: 14 May 2010 11:57 AM   [ Ignore ]   [ # 34 ]  
Grad Student
Rank
Total Posts:  35
Joined  03-03-2004

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.

Profile
 
 
Posted: 14 May 2010 12:12 PM   [ Ignore ]   [ # 35 ]  
Lab Assistant
RankRank
Total Posts:  191
Joined  02-23-2009

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?

Profile
 
 
Posted: 23 May 2010 10:47 PM   [ Ignore ]   [ # 36 ]  
Summer Student
Total Posts:  4
Joined  02-01-2010

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.

Profile
 
 
   
2 of 3
2