Skip to main content.
home | support | download

Back to List Archive

[swish-e] Pagination and sorting in PHP and a bit more

From: at <Timersys>
Date: Wed, 2 Nov 2011 17:21:28 -0300
Hi Guys, i need some help:
My swish-e version = 2.4.7
My OS: Linux  2.6.18-028stab070.14 #1 SMP Thu Nov 18 16:04:02 MSK 2010 x86_64 x86_64 x86_64 GNU/Linux
Scenario: Im using swish-e to index wordpress posts , pdf and doc files in a wordpress site.

My spider config file (test.config) :
  (at)not-real.servers = (
    {
        email               => 'admin(at)not-real.xxxx.com',
        link_tags           => [qw/ a frame /],
        keep_alive          => 1,
        base_url            => 'https://xxxx.com/wp-login.php?log=xxxxx&pwd=xxxxxx',
        ignore_robots_file       => 'true',
        credentials         =>'xxxx:xxxxxx',
        use_cookies         => 'true',
        use_default_config  => 'true',
    } );
----------------------
My swish.conf file :

IndexDir /usr/local/lib/swish-e/spider.pl

SwishProgParameters /usr/local/lib/swish-e/test.config

IndexContents HTML2 *
Metanames swishtitle swishdescription article author files category date

PropertyNames author files category
PropertyNamesDate date

StoreDescription TXT* 10000
StoreDescription HTML2 <article> 10000
StoreDescription HTML* <body> 10000

-------------------
I run the index # /usr/local/bin/swish-e -S prog -c swish-e.conf

1. My first question is how often shall index my site. Everytime a post is created or every 30 min or something like that? 

2. Can i use a cron job to do it? Any idea how to set up this in cPanel cron job settings ?

3. Here you can find my PHP file. I got not clue how limits results and pagination works. Also to choose different sort methods. As you see so far i used query for everything.



My PHP file is the following( I removed the form):

 <?php if (isset($_POST['q'])) { ?>

    <h2>Search Results</h2>

  <?php
    try {
      // create object
      $swish = new Swish('/usr/local/lib/swish-e/index.swish-e');

      // get and run query from command-line
      $queryStr = htmlentities($_POST['q']);
      $query=$queryStr;
      
      /**
      *	Categories Search
      */
      if($_POST['search_cats'][0] != ''):
      	$query .= ' AND category=(';
      	foreach($_POST['search_cats'] as $search_c):
      		$query .='('.$search_c.') OR';
      	endforeach;	
			$query = substr($query,0,-2);
			$query .=')';
      endif;
      
      
      /**
      * Authors Search
      */
      if($_POST['search_authors'][0] != ''):
      	$query .= ' AND author=(';
      	foreach($_POST['search_authors'] as $search_a):
      		$query .='('.$search_a.') OR';
      	endforeach;	
			$query = substr($query,0,-2);
			$query .=')';
      endif;
      
      /**
      * Date Search
      */
      if($_POST['search_date1'] != ''):
      //	$query .= ' AND date ">=" ';
      	$dt = new DateTime($_POST['search_date1']);
	//	$query .= $dt->format('U');
		
      endif;
      /**
      * THE SEARCHQUERY
      */
      
      $swish->prepare('SwishSetSearchLimit=10');
      $result = $swish->query($query);
  ?>

    Found <?php echo $result->hits; ?> match(es) for '<?php echo $queryStr; ?>'

  <?php
      // iterate over result set
      // print details for each match
      while($r = $result->nextResult()) {
  ?>

  <p>
    <?php echo $r->swishreccount; ?>.
    <strong>
      <a href="<?php echo $r->swishdocpath; ?>">
         <?php echo $r->swishtitle ? $r->swishtitle: $r->swishdocpath ; ?>
      </a>
      
    </strong> (score: <?php echo $r->swishrank; ?>) <br/>
    <?php echo $r->swishdocpath; ?>
  </p>
  <p>
  <?

$regex = '/[^.!?\n]*\b'.preg_quote($queryStr,"/").'\b[^.!?\n]*/i';

preg_match_all($regex, $r->swishdescription, $matches);  
count($matches[0]) > 3 ? $search_q= 3 : $search_q=count($matches[0]);

for ($i=0; $i < $search_q; $i++):
	echo preg_replace('/\b('.preg_quote($queryStr,"/").')\b/i','<span class="highlighted">$1</span>',$matches[0][$i]).'[..]  ';
endfor;
  	 ?>
  </p>
	<p>
	Last Modified: <? echo date('m-d-Y',$r->swishlastmodified);?>
	</p>

  <?php 
  
      }
    } catch (Exception $e) {
      die('ERROR: ' . $e->getMessage());
    }
  }
?>

///////END OF FILE
                                                
Hope the emails is not huge and someone can help me. I just pasted all the code just in case you need it , but maybe its not necessary to provide the answers.
Thanks once more

Damian Logghe,



_______________________________________________
Users mailing list
Users(at)not-real.lists.swish-e.org
http://lists.swish-e.org/listinfo/users
Received on Wed Nov 02 2011 - 20:21:37 GMT