0
I have the following search script, working very well, I would just like it to filter the search for words that have at least 3 characters.
<script> $(function(){ var regex = new RegExp('[\?]', 'g'); //
repare a flag "g" de global, para substituir todas as ocorrências
$('input').bind('input', function(){
$(this).val($(this).val().replace(regex, '')); }); }) </script>
<input type="text" placeholder="Digite sua pergunta" autofocus name="query" size="16" style="font-size: 11 pt; color: #000000;
font-family: Verdana; font-variant: small-; border: 1 solid #000000">
</font></font> <font face="Verdana, Arial, Helvetica, sans-serif" size="2">
<input type="submit" value="Buscar" style="font-size: 8 pt; color: #000000; font-family: Verdana; font-variant: small-caps;
border: 1 solid #000000">
</font>
</form> </center> </table> <table width="100%">
<tr>
<td height="0" bgcolor="#C0C0C0" width="100%"></td>
</tr> </table> </div> </center> <center> <div align="center" style="width: 100%; height: 100%"> <table width="80%">
<tr>
<!--<td width="100%"><font size="3" face="Verdana, Arial, Helvetica, sans-serif">-->
<td width="100%" style="font-size: 14px; color: #000000; font-family: Verdana; font-variant: small-; border: 1 solid #000000">
<script language="">
function removeAcento (text) {
text = text.toLowerCase ();
text = text.replace(new RegExp('[ÁÀÂÃ]','gi'), 'a');
text = text.replace(new RegExp('[ÉÈÊ]','gi'), 'e');
text = text.replace(new RegExp('[ÍÌÎ]','gi'), 'i');
text = text.replace(new RegExp('[ÓÒÔÕ]','gi'), 'o');
text = text.replace(new RegExp('[ÚÙÛ]','gi'), 'u');
text = text.replace(new RegExp('[Ç]','gi'), 'c');
return text; }
function kw_list () { this.keywords = new Array ();
this.num_words = 0;
this.query = "";
this.original_query = "";
this.query_length = 0;
this.possible_points = 0;
this.multiple = points_title + points_keywords + points_description;
this.get_words = get_query;
this.no_query = no_query_found; } function get_query () { this.query =
top.location.search.substring (top.location.search.indexOf ('=') + 1);
while ((the_plus = (this.query.indexOf ("+", 0))) != -1)
{
this.query_length = this.query.length;
this.query = this.query.substring (0, the_plus) + " " +
this.query.substring (the_plus + 1);
}
this.original_query = decodeURIComponent(this.query);
this.query = removeAcento(this.original_query);
this.query_length = this.query.length;
if (this.query != "")
{
var query_pointer = 0;
var end_word = 0;
var at_end = 0;
while ((this.num_words <= (max_keywords - 1)) && (! at_end))
{
end_word = this.query.indexOf (" ", query_pointer);
if (end_word == query_pointer)
query_pointer++;
else
{
if (end_word >= (this.query_length - 1))
at_end = 1;
if (end_word != -1)
this.keywords[this.num_words] = removeAcento(this.query.substring
(query_pointer, end_word));
else
{
this.keywords[this.num_words] = this.query.substring (query_pointer,
this.query_length);
at_end = 1;
}
this.num_words++;
if (query_pointer != -1)
query_pointer = end_word + 1;
if (query_pointer > (this.query_length - 1))
at_end = 1;
}
}
if (this.num_words == 0)
return (0);
else
{
this.possible_points = this.multiple * this.num_words;
return (1);
}
}
else
return (0);
}
function no_query_found ()
{
document.writeln ('<link rel="stylesheet" href="gp.css">');
document.writeln ('<CENTER><P>Pesquisa em branco.</P></CENTER>');
}
function entry (url, title, keywords, description)
{
this.url = url;
this.title = title;
this.keywords = keywords;
this.description = description;
this.points = 0;
this.search_entry = find_keyword;
this.print_entry = print_result;
}
function find_keyword (the_word)
{
var the_title = removeAcento(this.title);
var the_keywords = removeAcento(this.keywords);
var the_description = removeAcento(this.description);
if ((the_title.indexOf (the_word)) != -1)
this.points += points_title;
if ((the_keywords.indexOf (the_word)) != -1)
this.points += points_keywords;
if ((the_description.indexOf (the_word)) != -1)
this.points += points_description;
}
function print_result (possible_points)
{
document.writeln ('<CENTER><P><A HREF="' + this.url + '"
target="meio">' + this.title + '</A>' + this.description +
'</P></CENTER>');
}
function no_entry_printed (the_query)
{
document.writeln ('<link rel="stylesheet" href="gp.css">');
document.writeln ("<CENTER><P> Não há ocorrências para <U><B>" +
the_query + "</B></U>.</P></CENTER>");
}
function print_intro (the_query)
{
document.writeln ("<CENTER><P>Pesquisando por <U><B>" + the_query +
"</B></U>:</P></CENTER>");
}
function begin_search ()
{
var key_list = new kw_list;
var entry_printed = 0;
if (! key_list.get_words ())
key_list.no_query ();
else
{
var counter = 0;
var counter2 = 0;
for (counter = 0; counter < entry_num; counter++)
for (counter2 = 0; counter2 <= (key_list.num_words - 1); counter2++)
the_entries[counter].search_entry (key_list.keywords[counter2]);
for (counter = key_list.possible_points; counter > 0; counter--)
{
for (counter2 = 0; counter2 < entry_num; counter2++)
{
if (counter == the_entries[counter2].points)
{
if (entry_printed != 1)
{
entry_printed = 1;
print_intro (key_list.original_query);
}
the_entries[counter2].print_entry (key_list.possible_points);
}
}
}
if (! entry_printed)
no_entry_printed (key_list.original_query);
}
}
the_entries = new Array ();
//aqui vai as entradas para a pesquisa
//aqui vai as entradas para a pesquisa
the_entries[0] = new entry
( "http://leituracrista.com/o-que-respondi-volume-05/#1-coríntios-14-incentiva-as-línguas-para-a-edificação-própria","1 Co 14 incentiva as línguas para a edificação própria?"," dons,
línguas, profecia ","</br> <a
href='https://youtu.be/4CbaFLqR38Y?autoplay=1' target='_blank'><img
style='cursor:pointer;width:50px;height:40px;'
src='logos/youtube-2-1.svg'/></a>");
the_entries[1] = new entry
( "http://leituracrista.com/o-que-respondi-volume-06/#estas-passagens-dizem-que-podemos-perder-a-salva%C3%A7%C3%A3o","15
passagens que dizem que podemos perder a salvação?"," perder,
salvação, segurança ","</br> <a
href='https://youtu.be/Kgn6sKm3sdY?autoplay=1' target='_blank'><img
style='cursor:pointer;width:50px;height:40px;'
src='logos/youtube-2-1.svg'/></a>");
Miguel try to format your question to be visually pleasing and leave only the relevant parts of code please.
– BrTkCa
The condition
if (suaVar.legth >= 3)
doesn’t work?– Laércio Lopes
John Doe Thanks for answering, could you tell me where this function would be in my code above and which variable should I use, thank you
– Miguel Silva