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

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

Hmm, that seemed to be a problem with my .htaccess file: by adding php_flag display_errors on, to .htaccess in the root of the site, I get that error for every page. Have tried a couple of other ways to get htaccess to show PHP errors and they all have the same effect.

Any ideas? Thanks for your help and sorry if I’m missing something obvious - been staring at my screen for a long time now!

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

Yeah that’s just an error with your htaccess - never mind.

Could you let me know what version of PHP and MySQL you are running?

Also, have you considered that your zip decompressor might have corrupted the plugin file? Maybe you could check the plugin file with something like BBEdit’s Zap Gremlins, or just scan the code for odd looking characters…

Thanks

Mark

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

Yeah it was - I was using pretty standard stuff I thought, but 1&1 didn’t like it. I also just remembered that 1&1 defaults to PHP4 unless you tell it to use PHP5. Have fixed that, and your plugin now appears fine in the list! (Although now the rest of my site’s stopped working, but I think that’s something to do with PHP, not your plugin.)

Thanks for your help - sorry to miss such an obvious one!

       
The Nerdery's avatar
The Nerdery
16 posts
16 years ago
The Nerdery's avatar The Nerdery

Mark, here is a worthwhile addition to allow for querying against multiple weblogs:

// limit to a weblog?
        if ($weblog !== '*')
        {
            // Added by Brian Litzinger
            if(substr($delimiter, $weblog))
            {
                $weblogs = explode($delimiter, $weblog);
                $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 .= "AND wl.blog_name = '{$DB->escape_str($weblog)}'";
            }
        }
       
Frank Harrison's avatar
Frank Harrison
154 posts
16 years ago
Frank Harrison's avatar Frank Harrison

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?

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

@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 ‘<em>{embed:search_words}’</em>.
    {/if}
{/exp:search_fields}
       
smartpill's avatar
smartpill
456 posts
16 years ago
smartpill's avatar smartpill

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="http://{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?

       
11Media's avatar
11Media
157 posts
16 years ago
11Media's avatar 11Media

Are you making a version for EE 2.0 ?

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

@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.

       
Jim Pannell's avatar
Jim Pannell
187 posts
16 years ago
Jim Pannell's avatar Jim Pannell

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

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

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 😊

       
Jim Pannell's avatar
Jim Pannell
187 posts
16 years ago
Jim Pannell's avatar Jim Pannell

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

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

       
Bluebloc's avatar
Bluebloc
111 posts
16 years ago
Bluebloc's avatar Bluebloc

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

       
Mark Croxton's avatar
Mark Croxton
319 posts
16 years ago
Mark Croxton's avatar Mark Croxton

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/, notably the product section.

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

       
Bluebloc's avatar
Bluebloc
111 posts
16 years ago
Bluebloc's avatar Bluebloc

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="http://{page_url}">{title}</a>
{/exp:weblog:entries}

{/exp:search_fields}

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

Thanks again.

       
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.