fl=url,title

12 views
Skip to first unread message

Renato Gallo

unread,
Mar 14, 2014, 12:47:54 AM3/14/14
to php-sol...@googlegroups.com
i need to just display the url and the title in the search. I am using the example at the link: https://code.google.com/p/solr-php-client/wiki/ExampleUsage
how can I modify it to have just url and title ?


---------------------------------------------------------------code snippet-------------------------------------------------------------------------------------------------------------
<?php

// make sure browsers see this page as utf-8 encoded HTML
header
('Content-Type: text/html; charset=utf-8');

$limit
= 10;
$query
= isset($_REQUEST['q']) ? $_REQUEST['q'] : false;
$results
= false;

if ($query)
{
 
// The Apache Solr Client library should be on the include path
 
// which is usually most easily accomplished by placing in the
 
// same directory as this script ( . or current directory is a default
 
// php include path entry in the php.ini)
  require_once
('Apache/Solr/Service.php');

 
// create a new solr service instance - host, port, and webapp
 
// path (all defaults in this example)
  $solr
= new Apache_Solr_Service('localhost', 8180, '/solr/');

 
// if magic quotes is enabled then stripslashes will be needed
 
if (get_magic_quotes_gpc() == 1)
 
{
    $query
= stripslashes($query);
 
}

 
// in production code you'll always want to use a try /catch for any
 
// possible exceptions emitted  by searching (i.e. connection
 
// problems or a query parsing error)
 
try
 
{
    $results
= $solr->search($query, 0, $limit);
 
}
 
catch (Exception $e)
 
{
   
// in production you'd probably log or email this error to an admin
       
// and then show a special message to the user but for this example
       
// we're going to show the full exception
       
die("<html><head><title>SEARCH EXCEPTION</title><body><pre>{$e->__toString()}</pre></body></html>");
 
}
}

?>
<html>
 
<head>
   
<title>PHP Solr Client Example</title>
 
</head>
 
<body>
   
<form  accept-charset="utf-8" method="get">
     
<label for="q">Search:</label>
      <input id="q" name="q" type="text" value="
<?php echo htmlspecialchars($query, ENT_QUOTES, 'utf-8'); ?>"/>
     
<input type="submit"/>
   
</form>
<?php

// display results
if ($results)
{
  $total
= (int) $results->response->numFound;
  $start
= min(1, $total);
  $end
= min($limit, $total);
?>
   
<div>Results <?php echo $start; ?> - <?php echo $end;?> of <?php echo $total; ?>:</div>
   
<ol>
<?php
 
// iterate result documents
 
foreach ($results->response->docs as $doc)
 
{
?>
     
<li>
       
<table style="border: 1px solid black; text-align: left">
<?php
   
// iterate document fields / values
   
foreach ($doc as $field => $value)
   
{
?>
         
<tr>
           
<th><?php echo htmlspecialchars($field, ENT_NOQUOTES, 'utf-8'); ?></th>
           
<td><?php echo htmlspecialchars($value, ENT_NOQUOTES, 'utf-8'); ?></td>
         
</tr>
<?php
   
}
?>
       
</table>
     
</li>
<?php
 
}
?>
   
</ol>
<?php
}
?>
 
</body>
</html>
------------------------------------------end code snippet----------------------------------------------------------------

Donovan Jimenez

unread,
Mar 14, 2014, 12:56:44 AM3/14/14
to php-sol...@googlegroups.com
either use the fl parameter for just have the fields you want in the results, like your previous email, or instead of foreach'ing over the document, just directly reference the fields:

<?php echo htmlspecialchars($doc->title, ENT_NOQUOTES, 'utf-8'); ?>  

for example


--
You received this message because you are subscribed to the Google Groups "PHP Solr Client" group.
To unsubscribe from this group and stop receiving emails from it, send an email to php-solr-clie...@googlegroups.com.
To post to this group, send email to php-sol...@googlegroups.com.
Visit this group at http://groups.google.com/group/php-solr-client.
For more options, visit https://groups.google.com/d/optout.

Renato Gallo

unread,
Mar 14, 2014, 1:13:28 AM3/14/14
to php-sol...@googlegroups.com
It's a search engine for multiple sites I need foreach result of the query title and url.... where in this example should I put the fl?

https://code.google.com/p/solr-php-client/wiki/ExampleUsage
Reply all
Reply to author
Forward
0 new messages