Advertisement:

Author Topic: Add context to simple (quick) search  (Read 44192 times)

Offline pctwo

  • Semi-Newbie
  • *
  • Posts: 68
Add context to simple (quick) search
« on: September 07, 2006, 01:59:25 AM »
with 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.  This little change (which I haven't packaged into a nice mod b/c I haven't learned how to -- newbie alert!!) will show the user what context he's searching in and allows him to change it using a <select>.  So when he's at top level, there's no option.  When he's in a board, he can search the board or all.  When he's in a topic, he can search the topic, the board, or all.  Visual mockup (I can't post attachment)

Code: [Select]
____________ (search)   [ all         ]
                        [ this board  ]
                        [ this topic  ]

File:
Themes/name/index.template.php

Find:

   // Output any remaining HTML headers. (from mods, maybe?)
   echo $context['html_headers'], '

Add after

Code: [Select]
<script language="JavaScript" type="text/javascript"><!-- // --><![CDATA[
function search_context_change()
{
ctx =  document.quick_search.search_context.value;
if (ctx=="topic") {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
document.quick_search.topic_.name = "topic";
} else
if (ctx=="board") {
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
document.quick_search.board_.name = "brd["+document.quick_search.board_.value+"]";
} else {
if (document.quick_search.board_) document.quick_search.board_.name="dontuse";
if (document.quick_search.topic_) document.quick_search.topic_.name="donotuse";
}
}
// ]]></script>


find:

Code: [Select]
<form action="', $scripturl, '?action=search2" method="post"

change to (add name="quick_search")

Code: [Select]
<form name="quick_search" action="', $scripturl, '?action=search2" method="post"

replace block

Code: [Select]
// Search within current topic?
if (!empty($context['current_topic']))
echo '
<input type="hidden" name="topic" value="', $context['current_topic'], '" />';

// If we're on a certain board, limit it to this board ;).
elseif (!empty($context['current_board']))
echo '
<input type="hidden" name="brd[', $context['current_board'], ']" value="', $context['current_board'], '" />';

replace with

Code: [Select]
if (!empty($context['current_board']) || !empty($context['current_topic']))
{
echo '
<select onchange="javascript:search_context_change();" name="search_context">
<option value="all">', $txt['search_context_all'], '</option>';

$hidden_inputs = '';

if (!empty($context['current_board']))
{
echo '
<option value="board" ',
empty($context['current_topic'])
? 'selected="selected"' : '', '>', $txt['search_context_board'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="board_" name="' .
(empty($context['current_topic']) ? 'brd[' . $context['current_board'] . ']' : 'dontuse') .
'" value="' . $context['current_board'] . '" />';
}
if (!empty($context['current_topic']))
{
echo '
<option value="topic" selected="selected">', $txt['search_context_topic'], '</option>';
$hidden_inputs .= '
<input type="hidden" id="topic_" name="topic" value="' . $context['current_topic'] . '" />';
}
echo '
</select>', $hidden_inputs;
}

almost over!  now add to themes/name/languages/index.(lang).php

Code: [Select]
$txt['search_context_board'] = 'this board';
$txt['search_context_topic'] = 'this topic';
$txt['search_context_all'] = 'all';

hope that's useful :)
« Last Edit: September 08, 2006, 06:58:54 PM by pctwo »

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Tip: add context to simple (quick) search
« Reply #1 on: September 07, 2006, 02:15:34 AM »
This seems real cool. I can try to package it for you if you. Not tonight cause its late but if your interested PM me. :)
Tell us....Whats Ur Beef

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Tip: add context to simple (quick) search
« Reply #2 on: September 08, 2006, 06:20:20 PM »
I have started the package and now am in the testing phaze. I will do more tomorrow as there are some errors.
Tell us....Whats Ur Beef

Offline pctwo

  • Semi-Newbie
  • *
  • Posts: 68
Re: Tip: add context to simple (quick) search
« Reply #3 on: September 08, 2006, 07:01:51 PM »
oops, I messed up something in the original post.  I had id="quick_search" when it should've been name="quick_search".  I've tested this on Opera 9, IE 6, and Firefox 1.5.  I guess if you really want to be safe you should have both name and id :)

Offline JayBachatero

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,562
  • Gender: Male
    • @jaycreations on Twitter
    • JayBachatero.com
Re: Tip: add context to simple (quick) search
« Reply #4 on: September 08, 2006, 11:55:21 PM »
This is a nice Tip.  I was just about to suggest for you to package it up.  If you are interested take a look at Package SDK, anyone?.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #5 on: September 09, 2006, 02:06:45 AM »
Have you fixed your first post. ??? I will start over. I want to do it.

EDIT: unless you would like to try pctwo. ???
Tell us....Whats Ur Beef

Offline pctwo

  • Semi-Newbie
  • *
  • Posts: 68
Re: Add context to simple (quick) search
« Reply #6 on: September 09, 2006, 12:58:28 PM »
I'll learn how one of these days, but til then, please do it.  I'm more likely to mess something up :)

thanks, Bigguy.  And by all means give yourself credit, like "___ mod by Bigguy, based on a tip by pctwo"

edit: yes my first post should now be correct
« Last Edit: September 09, 2006, 01:06:30 PM by pctwo »

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #7 on: September 09, 2006, 01:40:13 PM »
I'll get on it today for you. If all goes well it might be done by tonight. (I hope) ;)
Tell us....Whats Ur Beef

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #8 on: September 09, 2006, 07:46:10 PM »
Having some major problems with this part of the one edit:

Code: [Select]
<!-- // --><![CDATA[
I don't think This can be in the middle of the code.
Tell us....Whats Ur Beef

Offline JayBachatero

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 19,562
  • Gender: Male
    • @jaycreations on Twitter
    • JayBachatero.com
Re: Add context to simple (quick) search
« Reply #9 on: September 10, 2006, 12:15:47 AM »
You can't.  Try using the board mod format instead of the .xml.
Follow me on Twitter

"HELP!!! I've fallen and I can't get up"
This moment has been brought to you by LifeAlert

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #10 on: September 10, 2006, 12:47:48 AM »
Ok, I'll give that a shot.  Thanks Jay.
Tell us....Whats Ur Beef

Offline pctwo

  • Semi-Newbie
  • *
  • Posts: 68
Re: Add context to simple (quick) search
« Reply #11 on: September 10, 2006, 10:27:34 AM »
Having some major problems with this part of the one edit:

Code: [Select]
<!-- // --><![CDATA[
I don't think This can be in the middle of the code.

I just copied that syntax without knowing what it does really.  what DOES it do?

Traditionally, you're supposed to wrap the entire script with <!-- --> so you don't confuse really old browsers, but that's hardly necessary nowadays.

Offline Dannii

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 10,211
  • Mind the volcano!
    • My homepage
Re: Add context to simple (quick) search
« Reply #12 on: September 10, 2006, 11:45:28 AM »
If your javascript has < > or & you need to put it in <![CDATA[ ]]> tags so that it is valid x(ht)ml. Javascript however won't understand that, so you need to comment it out with // tags first.
I'm not certain why the (x)html comments are needed to comment out the // though..

If you wrap the whole script in (x)html comments then moddern browsers might not run the script at all.
"Never imagine yourself not to be otherwise than what it might appear to others that what you were or might have been was not otherwise than what you had been would have appeared to them to be otherwise."

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #13 on: September 10, 2006, 01:27:08 PM »
Well, making a .mod file is a bit harder I think then making a .xml file. I keep getting a modification parse error, but I'm still trying. :)
Tell us....Whats Ur Beef

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #14 on: September 11, 2006, 05:10:10 PM »
Ok, I have not given up just got a bit busy. I will start on this again later tonight. :)
Tell us....Whats Ur Beef

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #15 on: September 13, 2006, 11:53:22 AM »
That one edit is still screwing me up is there another way to right that.
Tell us....Whats Ur Beef

Offline pctwo

  • Semi-Newbie
  • *
  • Posts: 68
Re: Add context to simple (quick) search
« Reply #16 on: September 13, 2006, 12:32:28 PM »
I think you can forget the cdata stuff

Code: [Select]
<script language="JavaScript" type="text/javascript"><!--

--></script>


php seems ok with it and it passes w3c validation.

I'm sorry you're having so much trouble.  I think it's harder to package this little mod up than to write it :(

P.S: I think we should change

$txt['search_context_all'] = 'all';

to

$txt['search_context_all'] = 'entire forum';

to make it clearer.
« Last Edit: September 13, 2006, 12:38:00 PM by pctwo »

Offline Bigguy

  • SMF Friend
  • SMF Super Hero
  • *
  • Posts: 12,307
  • Gender: Male
  • Be nice, or else....
    • smfbigguy on GitHub
    • SMF Helper
Re: Add context to simple (quick) search
« Reply #17 on: September 13, 2006, 12:59:56 PM »
Ok, I'll give that a try. I have had it packaged and installed but I keep getting parse errors and I don't think I am packing that cdata stuff right so I will try it without it.
Tell us....Whats Ur Beef

Offline Assistance

  • Jr. Member
  • **
  • Posts: 343
  • Gender: Male
Re: Add context to simple (quick) search
« Reply #18 on: November 06, 2006, 05:26:01 AM »
Quote
with 1.1RC3, we can now search in a topic using the simple (quick) search.  However, the user may not realize that when he's in a board, he's searching only the board if he uses the simple search, and when he's in a topic, he's searching only that topic.

some admins may not know that aswell  :-[
~playing poker~

Offline GaMerZ

  • Semi-Newbie
  • *
  • Posts: 16
  • Gender: Male
  • Complex Simplicity
    • Lester Chan's Website
Re: Add context to simple (quick) search
« Reply #19 on: December 28, 2006, 04:58:26 AM »
any news on this?