1
votes

I am trying to use solr PHP Client. When i tried to add the document it returning 400 status. I dont know what i am doing wrong and i am new to solr. Below is my code and schema.xml file.

I am using solr 4.10.3 and tomcat 7

Thanks in advance

$solr = new Apache_Solr_Service('localhost', '8080', '/solr/#/core0');    
if (!$solr->ping()) {
echo 'Solr service not responding.';
exit;
} else {
$fileContent = $_GET['fileContent'];
$title = trim($_GET['title']);
$desription = $_GET['description'];
$fileId = trim($_GET['fileId']);

$docs = array(
    'doc1' => array(
        'id' => 1,
        'fileid' => 'file1',
        'title' => 'title1'
));

$documents = array();
$part = new Apache_Solr_Document();
foreach ($docs as $item => $fields) {                
    foreach ($fields as $key => $value) {
        if (is_array($value)) {                        
            foreach ($value as $data) {
                $part->setMultiValue($key, $data);
            }
        }                    
        else {                           
            $part->$key = $value;
        }
    }                  

    $documents[] = $part;
}   
// Load the documents into the index

try {
    $a = $solr->addDocuments($documents);                
    $solr->commit();
    $solr->optimize();                    
} catch (Exception $e) {
    echo $e->getMessage();
}
die;
$offset = 0;
$limit = 10;  

$queries = array('id:'.$fileId);

foreach ($queries as $query) {
    $response = $solr->search($query, $offset, $limit);
    if ($response->getHttpStatus() == 200) {
        // print_r( $response->getRawResponse() );
        if ($response->response->numFound > 0) {
            echo "$query <br />";
            foreach ($response->response->docs as $doc) {
                echo "$doc->id $doc->title <br />";
            }
            echo '<br />';
        }
    } else {
        echo $response->getHttpStatusMessage();
    }
}
}
}

schema.xml

<schema name="example core zero" version="1.1">
  <fieldtype name="string"  class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
  <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
  <field name="_version_" type="long" indexed="true" stored="true"/>
  <field name="id" type="long" indexed="true" stored="true"/>
  <field name="fileid"    type="string"   indexed="true"  stored="true"  required="true"/>
  <field name="title"     type="string"   indexed="true"  stored="true" />

 <uniqueKey>id</uniqueKey>

</schema>
1
There's probably some more info in your Solr logs (see the "logging" tab in the Solr admin UI).Yann
Logg showing as 2/2/2015, 6:19:53 PM WARN RequestHandlers Multiple requestHandler registered to the same name: /update ignoring: org.apache.solr.handler.UpdateRequestHandler 2/2/2015, 6:21:39 PM ERROR ShowFileRequestHandler Can not find: admin-extra.menu-bottom.html [/usr/share/solr/example/multicore/core0/conf/admin-extra.menu-bottom.html]Sumesh Kumar

1 Answers

0
votes

At least one problem is:

the parameter: /solr/#/core0 in Apache_Solr_Service should be:

/solr/core0