added six custom queries

git-svn-id: http://yolanda.mister-muffin.de/svn@320 7eef14d0-6ed0-489d-bf55-20463b2d70db
This commit is contained in:
josch 2008-04-27 08:40:41 +00:00
parent dfd08fd2dd
commit 8d9a158957
6 changed files with 46 additions and 30 deletions

View file

@ -11,11 +11,19 @@
<string id="url_root">http://localhost</string><!-- MUST NOT end with trailing slash -->
<!-- search options -->
<string id="search_frontpage_one_query">* order:timestamp sort:descending</string>
<string id="search_frontpage_two_query">* order:viewcount sort:descending</string>
<string id="search_frontpage_three_query">* order:downloadcount sort:descending</string>
<string id="search_frontpage_size">3</string>
<string id="search_results_default">10</string>
<string id="search_results_max">500</string>
<string id="search_order_default">relevance</string><!-- a v.column in the videos table or relevance -->
<string id="search_sort_default">desc</string><!-- asc or desc -->
<!-- general page settings -->
<string id="page_locale">en-us</string>
<string id="page_xslt">xhtml.xsl</string>
<string id="page_results_pagesize_default">10</string>
<string id="page_results_pagesize_max">500</string>
<string id="page_tag_lenght_min">3</string>
<string id="page_tag_count">20</string>
<string id="page_openid">true</string>

View file

@ -22,9 +22,9 @@
<string id="path_root">http://localhost/</string>
<string id="path_upload">/upload.pl</string>
<string id="path_uploader">/uploader.pl</string>
<string id="path_query_latestadditions">/search.pl?query=*%20orderby:timestamp%20sort:descending</string>
<string id="path_query_mostdownloads">/search.pl?query=*%20orderby:downloadcount%20sort:descending</string>
<string id="path_query_mostviews">/search.pl?query=*%20orderby:viewcount%20sort:descending</string>
<string id="path_query_custom_one">/search.pl?query=*%20order:timestamp%20sort:descending</string>
<string id="path_query_custom_two">/search.pl?query=*%20order:downloadcount%20sort:descending</string>
<string id="path_query_custom_three">/search.pl?query=*%20order:viewcount%20sort:descending</string>
</strings>

View file

@ -56,10 +56,10 @@ sub fill_results
$resultcount = $sth->execute(@args) or die $dbh->errstr;
#set pagesize by query or usersettings or default
$pagesize = $query->param('pagesize') or $pagesize = $userinfo->{'pagesize'} or $pagesize = $config->{"page_results_pagesize_default"};
$pagesize = $query->param('pagesize') or $pagesize = $userinfo->{'pagesize'} or $pagesize = $config->{"search_results_default"};
#if pagesize is more than maxpagesize reduce to maxpagesize
$pagesize = $pagesize > $config->{"page_results_pagesize_max"} ? $config->{"page_results_pagesize_max"} : $pagesize;
$pagesize = $pagesize > $config->{"search_results_max"} ? $config->{"search_results_max"} : $pagesize;
#rediculous but funny round up, will fail with 100000000000000 results per page
#on 0.0000000000001% of all queries - this is a risk we can handle
@ -73,7 +73,7 @@ sub fill_results
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
#execute it
$sth->execute(@args) or die $dbquery;
$sth->execute(@args) or die $dbh->errstr;
$results->setAttribute('lastpage', $lastpage);
$results->setAttribute('currentpage', $currentpage);
@ -179,7 +179,7 @@ sub get_sqlquery
my $strquery = @_[0];
$strquery =~ s/%([0-9A-F]{2})/chr(hex($1))/eg;
(@tags) = $strquery =~ / tag:(\w+)/gi;
($orderby) = $strquery =~ / orderby:(\w+)/i;
($order) = $strquery =~ / order:(\w+)/i;
($sort) = $strquery =~ / sort:(\w+)/i;
#($title) = $strquery =~ /title:(\w+)/i;
#($description) = $strquery =~ /description:(\w+)/i;
@ -191,7 +191,7 @@ sub get_sqlquery
#($filesize) = $strquery =~ /filesize:([<>]?\w+)/i;
#($duration) = $strquery =~ /duration:([<>]?\w+)/i;
#($timestamp) = $strquery =~ /timestamp:([<>]?\w+)/i;
$strquery =~ s/ (tag|orderby|sort):\w+//gi;
$strquery =~ s/ (tag|order|sort):\w+//gi;
$strquery =~ s/^\s*(.*?)\s*$/$1/;
#build mysql query
@ -226,35 +226,35 @@ sub get_sqlquery
push @args, "$publisher";
}
if($orderby)
if($order)
{
if($orderby eq 'filesize')
if($order eq 'filesize')
{
$dbquery .= " order by v.filesize";
}
elsif($orderby eq 'duration')
elsif($order eq 'duration')
{
$dbquery .= " order by v.duration";
}
elsif($orderby eq 'viewcount')
elsif($order eq 'viewcount')
{
$dbquery .= " order by v.viewcount";
}
elsif($orderby eq 'downloadcount')
elsif($order eq 'downloadcount')
{
$dbquery .= " order by v.downloadcount";
}
elsif($orderby eq 'timestamp')
elsif($order eq 'timestamp')
{
$dbquery .= " order by v.timestamp";
}
elsif($orderby eq 'relevance' and $strquery)
elsif($order eq 'relevance')
{
$dbquery .= " order by relevance";
}
else
{
$dbquery .= " order by v.id";
$dbquery .= " order by $config->{'search_order_default'}";
}
if($sort eq "ascending")
@ -265,6 +265,10 @@ sub get_sqlquery
{
$dbquery .= " desc";
}
else
{
$dbquery .= " $config->{'search_sort_default'}";
}
}
return $dbquery, @args;

View file

@ -60,10 +60,7 @@ $sth->finish() or die $dbh->errstr;
$root->appendChild($tagcloud);
#TODO: make this configureable
@querystrings = ("* orderby:timestamp sort:descending", "*", "*");
foreach $strquery (@querystrings)
foreach $strquery ($config->{"search_frontpage_one_query"}, $config->{"search_frontpage_two_query"}, $config->{"search_frontpage_three_query"})
{
#new results block
my $results = XML::LibXML::Element->new( "results" );
@ -71,13 +68,13 @@ foreach $strquery (@querystrings)
#get query string and args
my ($dbquery, @args) = get_sqlquery($strquery);
$dbquery .= " limit 0, 3";
$dbquery .= " limit 0, $config->{'search_frontpage_size'}";
#prepare query
$sth = $dbh->prepare($dbquery) or die $dbh->errstr;
#execute it
$sth->execute(@args) or die $dbquery;
$sth->execute(@args) or die @args;
#foreach result, fill appropriate results hash
while (my ($id, $title, $description, $publisher, $timestamp, $creator,

View file

@ -35,6 +35,13 @@
<string id="query_latestadditions">new videos</string>
<string id="query_mostdownloads">most downloaded</string>
<string id="query_mostviews">popular videos</string>
<string id="search_frontpage_one">new videos</string>
<string id="search_frontpage_two">most downloaded</string>
<string id="search_frontpage_three">popular videos</string>
<string id="search_custom_one">new videos</string>
<string id="search_custom_two">most downloaded</string>
<string id="search_custom_three">popular videos</string>
<!-- errors -->
<string id="error_202c">Error 202c - Access forbidden by government.</string>

View file

@ -39,27 +39,27 @@
<li id="latestadditions">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$site_strings[@id='path_query_latestadditions']" />
<xsl:value-of select="$site_strings[@id='path_query_custom_one']" />
</xsl:attribute>
<xsl:value-of select="$locale_strings[@id='query_latestadditions']" />
<xsl:value-of select="$locale_strings[@id='search_custom_one']" />
</a>
</li>
<li id="mostviews">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$site_strings[@id='path_query_mostviews']" />
<xsl:value-of select="$site_strings[@id='path_query_custom_two']" />
</xsl:attribute>
<xsl:value-of select="$locale_strings[@id='query_mostviews']" />
<xsl:value-of select="$locale_strings[@id='search_custom_two']" />
</a>
</li>
<li id="mostdownloads">
<a>
<xsl:attribute name="href">
<xsl:value-of select="$site_strings[@id='path_query_mostdownloads']" />
<xsl:value-of select="$site_strings[@id='path_query_custom_three']" />
</xsl:attribute>
<xsl:value-of select="$locale_strings[@id='query_mostdownloads']" />
<xsl:value-of select="$locale_strings[@id='search_custom_three']" />
</a>
</li>