//
// Search form control function
//
$(document).ready(function(){
// Get default search box value from hidden label
$("#keywords").attr("value", $("#search label").text());
// Clear search box only if default value present
$("#keywords").focus(function(){
if ($(this).attr("value") == $("#search label").text()) {
$(this).attr("value", "");
}
});
});
Tag Archive for search
Search field content control
Extraction Search Pattern
{*}<h2>{%}</h2>{%}</div><ul class="{*}">{%}</ul>{*}<a class="commentslink" href="{%}">{*}</a>
Php string in string function
// php has no "in_string" function, so here's one...
function in_string($needle, $haystack, $insensitive = 0) {
if ($insensitive) {
return (false !== stristr($haystack, $needle)) ? true : false;
} else {
return (false !== strpos($haystack, $needle)) ? true : false;
}
}
PHP æ£è¦è¡¨ç¾ã‚’使用ã—ã¦æ–‡å—列を検索ã™ã‚‹
$str = '<a href="/index.html" target="_blank">PHPリファï¾ï¾šï¾ï½½</a>';
//大文å—ãƒ»å°æ–‡å—を区別ã—ã¦ãƒžãƒƒãƒãƒ³ã‚°ã‚’行ã†å ´åˆ
if( ereg( "href", $str ) ){
print "href ã«ãƒžãƒƒãƒã—ã¾ã—ãŸn";
}
//大文å—ãƒ»å°æ–‡å—を区別ã—ãªã„ã§ãƒƒãƒãƒ³ã‚°ã‚’行ã†å ´åˆ
if( eregi( "HREF", $str ) ){
print "HREF ã«ãƒžãƒƒãƒã—ã¾ã—ãŸï¼ˆå¤§æ–‡å—ãƒ»å°æ–‡å—ã¯ç„¡è¦–)n";
}
//後方å‚照を行ã†ã«ã¯ã€ç¬¬ä¸‰å¼•æ•°ã«é…列変数を指定ã™ã‚‹
if( ereg( "href="([^"]*)" target="([^"]*)"", $str, $matches) ){
for( $i = 0; $i < count($matches); $i++ ){
print $matches[$i] . "n";
//çµæžœã¯ä»¥ä¸‹ã®é †ã«å‡ºåŠ›ã•れる
//href="/index.html" target="_blank"
///index.html
//_blank
}
}
Google Custom Search Engine from a List of Links
<!-- Use of this code assumes agreement with the Google Custom Search Terms of Service. --> <!-- The terms of service are available at /coop/docs/cse/tos.html --> <form name="cse" id="searchbox_demo" action="http://www.google.com/cse"> <input type="hidden" name="cref" value="" /> <input name="q" type="text" size="40" /> <input type="submit" name="sa" value="Search" /> </form> <script type="text/javascript" src="http://www.google.com/cse/tools/onthefly?form=searchbox_demo"></script>
Recursive grep
grep pattern -r directory *.txt
Basic Uncommented Crappy Binary Radix Trie
class Fixnum
def to_b(l = <img src='http://www.snippetsmania.com/wp-includes/images/smilies/icon_cool.gif' alt='8)' class='wp-smiley' /> "0′" + self.to_s(2).rjust(l, "0")
end
def set?(i)
if((self & (1 << i)) != 0)
return true
else
return false
end
end
def bdiff(x)
ret = -1
32.downto(0) do |i|
if(self.set?(i) != x.set?(i))
ret = i
break
end
end
ret
end
end
class String
def to_ip
ip = 0
split(".").each_with_index do |octet, index|
ip |= (octet.to_i << ((3 - index)*8))
end
ip
end
end
class SimpleTrie
def initialize(width=32)
@@node ||= Struct.new(:right, :left, :pos, :key, :value, :color)
@root = @@node.new(nil, nil, width, 0, nil)
@root.right = @root
@root.left = @root
@width = width
@sz = 0
end
private
def srch(key, limit=nil)
cur = @root
prev = nil
while(((not prev) or (cur.pos < prev.pos)) and ((not limit) or cur.pos > limit))
prev = cur
if(key.set? cur.pos)
cur = cur.right
else
cur = cur.left
end
end
return cur, prev
end
public
def []=(key, val)
x, prev = srch(key)
bit = key.bdiff(x.key)
cur, prev = srch(key, bit)
node = @@node.new(nil, nil, bit, key, val)
if(key.set? bit)
node.right = node
node.left = cur
else
node.right = cur
node.left = node
end
if(key.set? prev.pos)
prev.right = node
else
prev.left = node
end
@sz += 1
return val
end
def walk
color = rand
walker = lambda do |x, dir, tab|
if(x.color != color)
tab.times { print " " }
puts "#{ dir } #{ x.key } ( #{ x.key.to_b } ) @ #{ x.pos }"
x.color = color
walker.call(x.right, "-> ", tab+1)
walker.call(x.left, "<- ", tab+1)
end
end
walker.call(@root, ". ", 0)
end
def [](key)
res, p = srch(key)
return res.value
end
end
Exclude some directories from grep
find . -name "*.html" ( -name 'dirFoo' -prune -o -name 'dirBar' -prune ) | xargs grep -n "THE_PATH_YOU_ARE_LOOKING_FOR"
MySQL search
Word searching
1.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('Keyword')
(Fastest)
2.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('+Keyword' IN BOOLEAN MODE)
(Fast)
3.
SELECT * FROM TABLE WHERE RLIKE '(^| +)Keyword($| +)'
OR
SELECT * FROM TABLE WHERE
RLIKE '([[:space:]]|[[:<:]])Keyword([[:space:]]|[[:>:]])'
(Slow)
Contains searching
1.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('Keyword*' IN BOOLEAN MODE)
(Fastest)
2.
SELECT * FROM TABLE WHERE FIELD LIKE 'Keyword%'
(Fast)
3.
SELECT * FROM TABLE WHERE MATCH (`field`) AGAINST ('*Keyword*' IN BOOLEAN MODE)
(Slow)
4.
SELECT * FROM TABLE WHERE FIELD LIKE '%Keyword%'
(Slow)
Recordsets
1.
SELECT SQL_CALC_FOUND_ROWS * FROM TABLE WHERE Condition LIMIT 0, 10
SELECT FOUND_ROWS()
(Fastest)
2.
SELECT * FROM TABLE WHERE Condition LIMIT 0, 10
SELECT COUNT(PrimaryKey) FROM TABLE WHERE Condition
(Fast)
3.
$result = mysql_query("SELECT * FROM table", $link);
$num_rows = mysql_num_rows($result);
(Very slow)
Joins
Use an INNER JOIN when you want the joining table to only have matching records that you specify in the join. Use LEFT JOIN when it doesn’t matter if the records contain matching records or not.
SELECT * FROM products
INNER JOIN suppliers ON suppliers.SupplierID = products.SupplierID
Returns all products with a matching supplier.
SELECT * FROM products
LEFT JOIN suppliers ON suppliers.SupplierID = products.SupplierID
WHERE suppliers.SupplierID IS NULL
Returns all products without a matching supplier.
Scrape Google from the command line
perl -e "$i=0;while($i<1000){sleep 1; open(WGET,qq/|xargs lynx -dump/);printf WGET qq{http://www.google.com/search?q=site:onemorebug.com&hl=en&start=$i&sa=N},$i+=10}" | grep "//[^/]*onemorebug.com/"
Category: Uncategorized |
Tags: aggregator, analysis, commandline, google, iterator, lynx, metrics, one-liners, perl, results, scraping, search, wget