Skip to content

Commit b2c8b34

Browse files
committed
Initial commit.
0 parents  commit b2c8b34

File tree

2 files changed

+478
-0
lines changed

2 files changed

+478
-0
lines changed

search-example.php

Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
<?php
2+
3+
function show_search_form(){
4+
if($_GET['keywords']){
5+
$value = "value=\"" . htmlentities($_GET['keywords']) ."\"";
6+
}else{
7+
$value = '';
8+
}
9+
$search_form = '
10+
<form method="get" id="header_search_form" action="search">
11+
<input type="search" class="menu_link" name="keywords" placeholder="Search" ' . $value . ' required>
12+
<input type="submit" value="GO" class="menu_link">
13+
</form>';
14+
15+
return $search_form;
16+
}
17+
18+
function show_search(){
19+
20+
if($_GET['keywords']){
21+
global $DB;
22+
23+
# configure search engine
24+
25+
# Set which table to look in
26+
$table = "pages";
27+
28+
# Set which of the feilds in that table should be searched
29+
$look_in = array('id','title','description','category','url','content','keywords');
30+
31+
# Set which fields results should be ranked by (a filed that is encluded twice will be given twice the ranking weight)
32+
$rank_by = array('title', 'title', 'description','url');
33+
34+
# Create the search object.
35+
$search = new search($_GET['keywords'],$table, $look_in, $rank_by);
36+
37+
# Optionally set search to match any keyword instead of all keywords
38+
$search->settings['greedy'] = true;
39+
40+
# Optionally set reqired conditions.
41+
# For example you could have a categories drop down in on your search page and pass the results to this method.
42+
# Or set the field to 'status' and the value to 'active' to only show items that are set to active in the database.
43+
# $search->set_required_conditions($field, $value);
44+
45+
# Optionally set a custom sort
46+
# Can be used to sort results by date or alphebetically rather then by relevence. (Second argument is optional and defults to SORT_ASC.)
47+
# $search->set_sortby('date', SORT_DESC);
48+
49+
# Return results formated as html edit the show_search_result_block() method to customize what fields are shown and how.
50+
# This urrently uses the photosynthesis paginate class to handle mutiple pages of results. That could be removed or swapped for your favorite pagenator.
51+
$search_results_html = $search->get_results_html();
52+
53+
# Alternatly return an array of ids instead
54+
# Set the field to use.
55+
$search->settings['id_field'] = 'id';
56+
57+
# Get a sorted single level array matching ids.
58+
$ids = $search->get_results_ids();
59+
60+
# The get_results_message() method returns a formatted message about how many results were found
61+
$out .= "<span class=\"small\">Found " . $search->get_results_message() ."</span> <br /><br />";
62+
$out .= $search_results;
63+
64+
}else{
65+
$out = "Please type what you would like to find in the search box at the upper right of the page.";
66+
}
67+
68+
return $out;
69+
}
70+
71+
?>

0 commit comments

Comments
 (0)