Thanks for the reply Erik!

Based on a previous page I used to return queries I've developed this code
below for the page I need to do all of the above.

CODE

<?php


$id = $_GET['id'];

$connection = mysqli_connect("localhost", "root", "onion", "collection") or
die ("Couldn't connect to MySQL");

define('SOLR_URL', 'http://localhost:8080/solr/');

function request($reqData, $type){

    $header[] = "Content-type: text/xml; charset=UTF-8";

    $session = curl_init();
    curl_setopt($session, CURLOPT_HEADER,         true);
    curl_setopt($session, CURLOPT_HTTPHEADER,     $header);
    curl_setopt($session, CURLOPT_URL,            SOLR_URL.$type);
    curl_setopt($session, CURLOPT_POSTFIELDS,     $reqData);
    curl_setopt($session, CURLOPT_RETURNTRANSFER, 1);
    curl_setopt($session, CURLOPT_POST,           1);

    $response = curl_exec($session);
    curl_close($session);

    return $response;
}

function solrQuery($q){
    $query =
"?q=".trim(urlencode($q))."qf=Message-ID&version=2.2&start=0&rows=999999&indent=on";
return $results = request("", "select".$query);

        }

echo "<html><head><title>IP E-mail</title>";
echo '<link rel="stylesheet" type="text/css" href="stylesheet.css" />';

echo '<script type="text/javascript">
<!--
function confirmation() {
        var answer = confirm("Remove spam?")
        if (answer){
                alert("Spam removed!")
                $results = solrQuery('.$id.');
        }

}
//-->
</script>';


echo "</head><body>";


echo '<form method="post">';
echo '<table width="100%">';
echo "<tr>";
echo '<td><h1>Trace/Mark IP E-mail</h1><td>';
echo '<td><p align="right">Powered by</p></td>';
echo '<td width="283px"> mysql_logo.jpg </td>';
echo "</tr>";
echo "</table>";
echo "</form>";

/* Send a query to the server */ 
if ($location = mysqli_query($connection, "SELECT location FROM hashes WHERE
message_id = '$id'")) { 

echo '<br/>';
echo '<p>Mark as: <input type="button" onclick="confirmation()"
value="Spam"> <input type="button" value="Non-Business"> <input
type="button" value="Non-Confidential"></p>';

print("<h3>Message Location:\n</h3>"); 

/* Fetch the results of the query */ 
while( $row = mysqli_fetch_assoc($location) ){ 
printf("<p>%s\n</p>", $row['location']); 
} 

/* Destroy the result set and free the memory used for it */ 
mysqli_free_result($location); 
} 


/* Send a query to the server */ 
if ($duplicates = mysqli_query($connection, "SELECT location FROM hashes
WHERE (md5 = (SELECT md5 FROM hashes WHERE message_id = '$id') AND
message_id <> '$id')")) { 

print("<h3>Duplicate Locations:\n</h3>"); 

/* Fetch the results of the query */ 
while( $row = mysqli_fetch_assoc($duplicates) ){ 
printf("<p>%s\n</p>", $row['location']); 
} 

/* Destroy the result set and free the memory used for it */ 
mysqli_free_result($duplicates); 
} 




/* Close the connection */ 
mysqli_close($connection); 




    
 
                
        $results =
            explode('<?xml version="1.0" encoding="UTF-8"?>', $results);
        $results = $results[1];

        $dom = new DomDocument;
        $dom->loadXML($results);
        $docs = $dom->getElementsByTagName('doc');

        foreach ($docs as $doc) {
            $strings = $doc->getElementsByTagName('arr');
            foreach($strings as $str){
                $attr = $str->getAttribute('name');
                $data = $str->textContent;
                switch($attr){
                case 'Bcc':
                    $Bcc = $data;
                    break;
                case 'Cc':
                    $Cc = $data;
                    break;                                      
                case 'Content':
                    $Content = $data;
                    break;
                case 'Content-Transfer-Encoding':
                    $ContentTransferEncoding = $data;
                    break;
                case 'Content-Type':
                    $ContentType = $data;
                    break;
                case 'Date':
                    $Date = $data;
                    break;
                case 'From':
                    $From = $data;
                    break;
                case 'Message-ID':
                    $MessageID = $data;
                    break;
                case 'Mime-Version':
                    $MimeVersion = $data;
                    break;
                case 'Subject':
                    $Subject = $data;
                    break;
                case 'To':
                    $To = $data;
                    break;
                case 'X-FileName':
                    $XFileName = $data;
                    break;
                case 'X-Folder':
                    $XFolder = $data;
                    break;
                case 'X-From':
                    $XFrom = $data;
                    break;
                case 'X-Origin':
                    $XOrigin = $data;
                    break;
                case 'X-To':
                    $XTo = $data;
                    break;
                case 'X-bcc':
                    $Xbcc = $data;
                    break;
                case 'X-cc':
                    $Xcc = $data;
                    break;
                }
            }
                        
        }
    
        
echo "</body></html>";




?>
/CODE


The issue I'm having is working out how to use this to submit a POST delete
Solr query on a button click, or how to use the document (once returned,
like the query page) and save it in text form to disk (essentially,
excluding all XML mark-up)...is this done using Curl (supported)...or AJAX?


Any ideas?


Cheers.





Erik Hatcher wrote:
> 
> 
> On Apr 10, 2009, at 8:36 PM, Johnny X wrote:
>> How could I write some code in PHP to place in a button to remove a  
>> returned
>> item from the index?
> 
> You can issue a delete command to Solr by simply doing a GET (or POST)  
> to
> http://localhost:8983/solr/update?stream.body=%3Cdelete%3E%3Cid%3ESOMEID%3C/id%3E%3C/delete%3Eete%3E%3Cquery%3Esome:query%3C/query%3E%3C/delete%3E&commit=true
> 
> (replace SOMEID with whatever unique id you want, or switch to use the  
> delete-by-query)
> 
>> In turn, is it possible to copy all of the XML elements from said  
>> item and
>> place them in a document somewhere locally once it's been removed?
> 
> You could do a /select?q=id:SOMEID&fl=* and get all stored field  
> values (note you'll lose any unstored values) and stash those results  
> off however you like.
> 
>> Finally, there is one default search field. How do you search on  
>> multiple
>> different fields in PHP?
> 
> Use the dismax parser.  /select? 
> q=whatever&defType=dismax&qf=field1+field2
> 
> See the wiki docs on dismax for more details and list of other  
> parameters.
> 
>> If I wanted to search by all of the fields indexed, is that easy to  
>> code?
> 
> You could list all fields in the qf field of dismax.
> 
> Another option is to copyField all fields you want searchable into a  
> single field and search that single field.
> 
>> What changes do I need to make in the XML schema?
> 
> To use dismax, no changes to schema are needed (necessarily).
> 
> But you may want to add copyField's to schema.xml to collect all field  
> text into a single field for default field searchability.
> 
>       Erik
> 
> 

-- 
View this message in context: 
http://www.nabble.com/PHP-Remove-From-Index-Search-By-Fields-tp22996701p23016677.html
Sent from the Solr - User mailing list archive at Nabble.com.

Reply via email to