简体   繁体   中英

php arrays into solr index

I've been using mysql just to practice getting data stored. What I do is get the textnodes of an html document, its y coordinate relative to the document, and the url. I was wondering how I could do this straight into solr (since it uses xml). Some general guidance would be great as well.

for($i=0; $i<count($textnode); $i++) {

$textnode[$i] = stripslashes($textnode[$i]);
$textnode[$i] = mysql_real_escape_string($textnode[$i], $con);



 mysql_query("INSERT INTO paragraphs (paragraphs, ytext, url)
 VALUES ('$textnode[$i]','$ytext[$i]', '$url')");



}

You take an available xml document library(there are more than one the most simple would be probably SimpleXML ) in your php script. XML Format of solr is described in their wiki( see here ).

You add then your fields to the document with some names(as configured by your schema.xml). And post it to the solr interface.

See eg the example using curl. PHP has also a curl library. So you can implement anything there with ease.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM