Fix accept header in crawler
[phinde.git] / src / phinde / Indexer.php
index 98b52c3a22304da42e9858e7d0588e5b7e5c2eab..4885b7a9fb86e1cbbb09cda23806925e82f66adc 100644 (file)
@@ -4,8 +4,8 @@ namespace phinde;
 class Indexer
 {
     static $supportedTypes = array(
-        'application/xhtml+xml',
-        'text/html',
+        'application/xhtml+xml' => true,
+        'text/html'             => true,
     );
 
     public function run(Retrieved $retrieved)
@@ -16,15 +16,13 @@ class Indexer
 
         $mimetype = explode(';', $res->getHeader('content-type'))[0];
         if (!in_array($mimetype, static::$supportedTypes)) {
-            echo "MIME type not supported for indexing: $mimetype\n";
+            Log::info("MIME type not supported for indexing: $mimetype");
             return false;
         }
 
         if ($esDoc === null) {
-            $esDoc = new \stdClass();
-        }
-        if (!isset($esDoc->status)) {
-            $esDoc->status = new \stdClass();
+            $esDoc = Helper::baseDoc($url);
+            $retrieved->esDoc = $esDoc;
         }
 
         //FIXME: update index only if changed since last index time
@@ -52,8 +50,8 @@ class Indexer
             $robots = $meta->attributes->getNamedItem('content')->textContent;
             foreach (explode(',', $robots) as $value) {
                 if (trim($value) == 'noindex') {
-                    echo "URL does not want to be indexed: $url\n";
-                    exit(0);
+                    $esDoc->status->findable = false;
+                    return true;
                 }
             }
         }
@@ -188,7 +186,6 @@ class Indexer
 
         //var_dump($esDoc);die();
 
-        $retrieved->esDoc = $esDoc;
         return true;
     }