Permalink
Browse files

Adding SOLR schema, reset script and docs loader prototype

  • Loading branch information...
1 parent f54b26a commit a1fca5feafbafb5ab7fba141dc90b0775753455e @fakedarren committed Apr 29, 2012
Showing with 764 additions and 2 deletions.
  1. +1 −2 .gitignore
  2. +16 −0 SOLR/delete-all.php
  3. +98 −0 SOLR/loader/docs.php
  4. +649 −0 SOLR/schema.xml
View
@@ -1,3 +1,2 @@
-SOLR
.DS_Store
-assets/mootools
+assets/mootools
View
@@ -0,0 +1,16 @@
+
+<?php
+include('../application/lib/Solarium/Autoloader.php');
+Solarium_Autoloader::register();
+$client = new Solarium_Client();
+
+$update = $client->createUpdate();
+$update->addDeleteQuery('name:**');
+$update->addCommit();
+
+$result = $client->update($update);
+
+echo '<b>Update query executed<b><br/>';
+echo 'Query status: ' . $result->getStatus(). '<br/>';
+echo 'Query time: ' . $result->getQueryTime();
+?>
View
@@ -0,0 +1,98 @@
+<?php
+include('../../application/lib/Solarium/Autoloader.php');
+Solarium_Autoloader::register();
+$client = new Solarium_Client();
+
+
+/*
+helpers
+*/
+function array_flatten($array){
+ foreach($array as $key => $value)
+ $array[$key] = (array)$value;
+ return call_user_func_array('array_merge', $array);
+}
+
+function getAllFilesIn($directory){
+ $dirs = scandir($directory);
+ foreach($dirs as $file){
+ if ($file[0] != '.' && $file != 'menu.html'){
+ if (is_dir($directory . '/' . $file)){
+ $results[] = getAllFilesIn($directory . '/' . $file);
+ } else {
+ $results[] = $directory . '/' . $file;
+ }
+ }
+ }
+ return array_flatten($results);
+}
+
+
+/*
+get content
+*/
+foreach (getAllFilesIn('../../releases/2.0') as $page){
+ $content = file_get_contents($page);
+
+ $dom = new DOMDocument();
+ $dom->loadHTML($content);
+
+ $xpath = new DOMXpath($dom);
+
+ $headings = $dom->getElementsByTagName('h1');
+
+ $doc = new Solarium_Document_ReadWrite();
+ $doc->id = md5($page);
+ $doc->name = $headings->item(0)->nodeValue;
+ $doc->content = $content;
+
+ $results[] = $doc;
+}
+
+
+/*
+write content
+*/
+$update = $client->createUpdate();
+
+$update->addDocuments($results);
+$update->addCommit();
+
+$result = $client->update($update);
+
+echo '<b>Update query executed<b><br/>';
+echo 'Query status: ' . $result->getStatus(). '<br/>';
+echo 'Query time: ' . $result->getQueryTime() . '<hr/><br/><br/><br/><br/><br/><br/>';
+
+// create a client instance
+$client = new Solarium_Client();
+
+// get a select query instance
+$query = $client->createSelect();
+
+// override the default row limit of 10 by setting rows to 30
+$query->setRows(30);
+
+// this executes the query with default settings and returns the result
+$resultset = $client->select($query);
+
+// display the total number of documents found by solr
+echo 'NumFound: '.$resultset->getNumFound();
+
+// show documents using the resultset iterator
+foreach ($resultset as $document) {
+
+ echo '<hr/><table>';
+
+ // the documents are also iterable, to get all fields
+ foreach($document AS $field => $value)
+ {
+ // this converts multivalue fields to a comma-separated string
+ if(is_array($value)) $value = implode(', ', $value);
+
+ echo '<tr><th>' . $field . '</th><td>' . $value . '</td></tr>';
+ }
+
+ echo '</table>';
+}
+?>
Oops, something went wrong.

0 comments on commit a1fca5f

Please sign in to comment.