From d577367cbb215263f73dd9241d93462f9518de1b Mon Sep 17 00:00:00 2001
From: Andrea Zagli <azagli@libero.it>
Date: Sat, 2 Jan 2010 15:17:17 +0100
Subject: [PATCH] Bugfixes. Pagination. Some search parameters.

---
 .../admin/en-GB.com_jmnogosearch.ini          | 19 ++++++++++++
 .../site/en-GB.com_jmnogosearch.ini           | 27 ++++++++++++++++
 com_jmnogosearch/site/models/jmnogosearch.php | 31 +++++++++++++++----
 .../views/jmnogosearch/tmpl/default_form.php  |  4 +--
 .../jmnogosearch/tmpl/default_results.php     |  9 ++++--
 .../site/views/jmnogosearch/view.html.php     |  7 +++--
 6 files changed, 83 insertions(+), 14 deletions(-)
 create mode 100755 com_jmnogosearch/admin/en-GB.com_jmnogosearch.ini
 create mode 100755 com_jmnogosearch/site/en-GB.com_jmnogosearch.ini

diff --git a/com_jmnogosearch/admin/en-GB.com_jmnogosearch.ini b/com_jmnogosearch/admin/en-GB.com_jmnogosearch.ini
new file mode 100755
index 0000000..3d1b435
--- /dev/null
+++ b/com_jmnogosearch/admin/en-GB.com_jmnogosearch.ini
@@ -0,0 +1,19 @@
+# $Id: en-GB.com_search.ini 10388 2008-06-03 11:16:20Z pasamio $
+# Joomla! Project
+# Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
+# License http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
+# Note : All ini files need to be saved as UTF-8 - No BOM
+
+DESCSEARCH=This Component manages the Search functionality.
+GATHER SEARCH STATISTICS=Gather Search Statistics
+HIDE SEARCH RESULTS=Hide Search Results
+RESULTS RETURNED=Results Returned
+SEARCH LOGGING=Search Logging
+SEARCH STATISTICS=Search Statistics
+SEARCH TEXT=Search Text
+SHOW CREATED DATE=Show Created Date
+SHOW SEARCH RESULTS=Show Search Results
+STANDARD SEARCH FORM=Standard Search Form
+STANDARD SEARCH LAYOUT DESC=The standard Search layout displays the Search Form and result.
+TIMES REQUESTED=Times Requested
+TIPSEARCHSTATISTICS=Enable/Disable collection of site statistics
\ No newline at end of file
diff --git a/com_jmnogosearch/site/en-GB.com_jmnogosearch.ini b/com_jmnogosearch/site/en-GB.com_jmnogosearch.ini
new file mode 100755
index 0000000..718e104
--- /dev/null
+++ b/com_jmnogosearch/site/en-GB.com_jmnogosearch.ini
@@ -0,0 +1,27 @@
+# $Id: en-GB.com_search.ini 10498 2008-07-04 00:05:36Z ian $
+# author Joomla! Project
+# Copyright (C) 2005 - 2008 Open Source Matters. All rights reserved.
+# license http://www.gnu.org/licenses/gpl-2.0.html GNU/GPL, see LICENSE.php
+
+# Note : All ini files need to be saved as UTF-8
+
+ALL WORDS=All words
+ALPHABETICAL=Alphabetical
+ANY WORDS=Any words
+DISPLAY NUM=Display #
+EXACT PHRASE=Exact Phrase
+IGNOREKEYWORD=One or more common words were ignored in the search.
+RELEVANCY=Relevancy
+NEWEST FIRST=Newest First
+NO RESULTS WERE FOUND=No results were found.
+OLDEST FIRST=Oldest First
+ORDERING=Ordering
+SEARCH=Search
+SEARCH KEYWORD=Search Keyword
+SEARCH_MESSAGE=Search term must be a minimum of 3 characters and a maximum of 20 characters.
+SEARCH ONLY=Search Only
+TOTALRESULTSFOUND=Total: %s results found.
+WITH=with
+SEARCH_AGAIN=Search Again
+SEARCH_RESULT=Search Result
+SEARCH PARAMETERS=Search Parameters
diff --git a/com_jmnogosearch/site/models/jmnogosearch.php b/com_jmnogosearch/site/models/jmnogosearch.php
index 4e4abbf..8c2dd21 100644
--- a/com_jmnogosearch/site/models/jmnogosearch.php
+++ b/com_jmnogosearch/site/models/jmnogosearch.php
@@ -69,7 +69,7 @@ class JMnoGoSearchModelJMnoGoSearch extends JModel
 		// Set the search parameters
 		$keyword = urldecode(JRequest::getString('searchword'));
 		$match = JRequest::getWord('searchphrase', 'all');
-		$ordering = JRequest::getWord('ordering', 'newest');
+		$ordering = JRequest::getWord('ordering', 'relevancy');
 		$this->setSearch($keyword, $match, $ordering);
 	}
 
@@ -113,14 +113,33 @@ class JMnoGoSearchModelJMnoGoSearch extends JModel
 			$keyword = $this->getState('keyword');
 			if (trim($keyword) != '')
 			{
+				$ordering = $this->getState('ordering');
+				$match = $this->getState('match');
+
+				if ($ordering == 'relevancy') {
+				} else if ($ordering == 'newest') {
+				} else if ($ordering == 'older') {
+				} else if ($ordering == 'title') {
+				}
+
+				if ($match == 'all') {
+					udm_set_agent_param ($this->_agent, UDM_PARAM_SEARCH_MODE, UDM_MODE_ALL);
+				} else if ($match == 'any') {
+					udm_set_agent_param ($this->_agent, UDM_PARAM_SEARCH_MODE, UDM_MODE_ANY);
+				} else if ($match == 'exact') {
+					udm_set_agent_param ($this->_agent, UDM_PARAM_SEARCH_MODE, UDM_MODE_PHRASE);
+				}
+
+				$limit = $this->getState('limit');
+				$limitstart = $this->getState('limitstart');
+				udm_set_agent_param ($this->_agent, UDM_PARAM_PAGE_SIZE, $limit);
+
+				$npage = $limitstart / $limit;
+				udm_set_agent_param ($this->_agent, UDM_PARAM_PAGE_NUM, $npage);
+
 				$mResult = udm_find ($this->_agent, $keyword);
 
 				$this->_total = udm_get_res_param ($mResult, UDM_PARAM_FOUND);
-				/*if ($this->getState('limit') > 0) {
-					$this->_data = array_splice($rows, $this->getState('limitstart'), $this->getState('limit'));
-				} else {
-					$this->_data = $rows;
-				}*/
 				$this->_data = $mResult;
 			} else {
 				$this->_total = 0;
diff --git a/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_form.php b/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_form.php
index 4eab7ce..7a53507 100644
--- a/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_form.php
+++ b/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_form.php
@@ -52,10 +52,10 @@
 		<label for="limit">
 			<?php echo JText::_( 'Display Num' ); ?>
 		</label>
-		<?php //echo $this->pagination->getLimitBox( ); ?>
+		<?php echo $this->pagination->getLimitBox( ); ?>
 	</div>
 	<div>
-		<?php //echo $this->pagination->getPagesCounter(); ?>
+		<?php echo $this->pagination->getPagesCounter(); ?>
 	</div>
 </div>
 <?php endif; ?>
diff --git a/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_results.php b/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_results.php
index dd3eff0..7cba39f 100644
--- a/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_results.php
+++ b/com_jmnogosearch/site/views/jmnogosearch/tmpl/default_results.php
@@ -4,11 +4,12 @@
 	<tr>
 		<td>
 		<?php
+		if ($this->total > 0) {
 		foreach( $this->results as $result ) : ?>
 			<fieldset>
 				<div>
 					<span class="small<?php echo $this->escape($this->params->get('pageclass_sfx')); ?>">
-						<?php echo $this->pagination->limitstart + $result->count.'. ';?>
+						<?php echo $result->count.'. ';?>
 					</span>
 					<?php if ( $result->href ) :
 						if ($result->browsernav == 1 ) : ?>
@@ -32,13 +33,15 @@
 				</div>
 				<?php endif; ?>
 			</fieldset>
-		<?php endforeach; ?>
+		<?php endforeach;
+			}
+		?>
 		</td>
 	</tr>
 	<tr>
 		<td colspan="3">
 			<div align="center">
-				<?php //echo $this->pagination->getPagesLinks( ); ?>
+				<?php echo $this->pagination->getPagesLinks( ); ?>
 			</div>
 		</td>
 	</tr>
diff --git a/com_jmnogosearch/site/views/jmnogosearch/view.html.php b/com_jmnogosearch/site/views/jmnogosearch/view.html.php
index e2771b7..8ed961d 100644
--- a/com_jmnogosearch/site/views/jmnogosearch/view.html.php
+++ b/com_jmnogosearch/site/views/jmnogosearch/view.html.php
@@ -108,15 +108,16 @@ class JMnoGoSearchViewJMnoGoSearch extends JView
 
 			$results = &$this->get('data');
 			$total = &$this->get('total');
-			//$pagination = &$this->get('pagination');
+			$pagination = &$this->get('pagination');
 
 			require_once (JPATH_SITE.DS.'components'.DS.'com_content'.DS.'helpers'.DS.'route.php');
 
-			if ($results != null)
+			if ($total > 0)
 			{
 				$firstRow = udm_get_res_param ($results, UDM_PARAM_FIRST_DOC);
 				$lastRow = udm_get_res_param ($results, UDM_PARAM_LAST_DOC);
-				for ($i = $firstRow - 1; $i < $lastRow; $i++)
+				$rows = $lastRow - $firstRow + 1;
+				for ($i = 0; $i < $rows; $i++)
 				{
 					$row = new stdClass();
 					$row->text = udm_get_res_field ($results, $i, UDM_FIELD_TEXT);
-- 
2.49.0