Hi Derick,
thanks for your answer.
Am Monday 23 March 2009 13:37:43 schrieb Derick Rethans:
> On Mon, 23 Mar 2009, Thomas Koch wrote:
> > 4) Indexing only one document at a time
> >
> > Unfortunatly I did not run a benchmark before I changed my code, but it
> > felt much slower afterwards. I believe the main reason is, that I can
> > index only one document at a time with ezcSearch, while I sent 200
> > documents with one request in my hand crafted version.
>
> That's not true, you can use transactions:
I did put it in a transaction, but there is still one HTTP POST for each
document.
I made a quick refactor and used the code from the solr handler to send
200 documents in one HTTP request.
function indexArticles( ezcSearchSolrHandler $solr, Array $articles, Array
$mapping )
{
if( empty( $articles ) ) return;
$xml = new XmlWriter();
$xml->openMemory();
$xml->startElement( 'add' );
foreach( $articles as $article )
{
$state = $article->getState();
$xml->startElement( 'doc' );
foreach ( $mapping as $field => $property )
{
$xml->startElement( 'field' );
$xml->writeAttribute( 'name', $field );
$xml->text( $state[$property] );
$xml->endElement();
}
$xml->endElement();
}
$xml->endElement();
$doc = $xml->outputMemory( true );
$r = $solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ), $doc );
$r = $solr->sendRawPostCommand( 'update', array( 'wt' => 'json' ),
'<commit/>' );
}
According to xdebug the total code execution time dropped from 3.8E6 to 2.2E6.
I tried to put the above function into the solr handler and call it from
ezcSearchSolrHandler::index(), but it did not work, since I want to
avoid calling mapFieldValueForIndex.
Idea: Why not throw the whole mapping stuff out of the solr handler and
use optional value converter like for PO?
Best regards,
--
Thomas Koch, http://www.koch.ro
--
Components mailing list
[email protected]
http://lists.ez.no/mailman/listinfo/components