Search results.

A place for users and developers of the Xataface to discuss and receive support.

Postby vlad » Wed Jul 18, 2007 2:16 pm

How can I limit the search results found? If someone tries a blank search he can access all my records. I would like to give him an error to tell him to refine his search, or to display only 10 or so records.

Excuse my english. Thank you
vlad
 
Posts: 28
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jul 20, 2007 12:37 am

Dataface uses the -limit GET parameter to set the number of records. So if you add this parameter at the beginning of your index.php file, it will enforce a limit;

e.g.
index.php:
Code: Select all
if ( !isset($_GET['-limit']) ){
    $_GET['-limit'] = 10;
    $_REQUEST['-limit'] = 10;
}
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm

Postby vlad » Fri Jul 20, 2007 2:53 am

This only changes the number of records showned per page. From 30 to 10. The user still has the ability to browse through all my 8000 records if he enters a blank search.
vlad
 
Posts: 28
Joined: Wed Dec 31, 1969 5:00 pm

Postby vlad » Fri Jul 20, 2007 3:14 am

For now , it is done in some rudimentary way. If user tries to search for a string that will display too many results it will give him an error. I've tried to limit the search results displayed by forcing the user to search for more than three characters.

if ( isset($_GET['-search']) ){
if(strlen($_GET['-search']) < 3) {
header('Location: http://www.blah.com/error');
}
}

Someone can still browse through my database by entering a blank search in the advanced search form (-action=find).
vlad
 
Posts: 28
Joined: Wed Dec 31, 1969 5:00 pm

Postby vlad » Fri Jul 20, 2007 5:45 am

I think this is a pretty clean approach. in ResultList.php

if ( $this->_resultSet->found() > 0 && $this->_resultSet->found() < 100) {
...
}
elseif($this->_resultSet->found() > 100) {
....
} else {
....
}
vlad
 
Posts: 28
Joined: Wed Dec 31, 1969 5:00 pm

Postby shannah » Fri Jul 20, 2007 8:46 am

Yes.. you're on the right track.

In your index.php file:
$resultSet =& $app->getResultSet();
$resultSet->loadSet();
if ( $resultSet->found() > 100 ){ ....}
else { ...}
--
Steve Hannah
@shannah78 (on twitter)
sjhannah.com blog
shannah
 
Posts: 4457
Joined: Wed Dec 31, 1969 5:00 pm


Return to Xataface Users

Who is online

Users browsing this forum: No registered users and 27 guests

cron
Powered by Dataface
© 2005-2007 Steve Hannah All rights reserved