3 Commits

Author SHA1 Message Date
  Chimo 66bd973fb2 Index both notice 'verb' and 'type' 1 year ago
  Chimo 25cd3e1b13 Handle "no results" 1 year ago
  Chimo 88d4bfb779 Some error handling 1 year ago
1 changed files with 13 additions and 37 deletions
  1. 13
    37
      lib/ElasticSearch.php

+ 13
- 37
lib/ElasticSearch.php View File

@@ -43,9 +43,6 @@ class ElasticSearch extends SearchEngine
43 43
                     'text' => [
44 44
                         'type' => 'string'
45 45
                     ],
46
-                    'verb' => [
47
-                        'type' => 'string'
48
-                    ],
49 46
                     'type' => [
50 47
                         'type' => 'string'
51 48
                     ],
@@ -90,14 +87,9 @@ class ElasticSearch extends SearchEngine
90 87
                 ]
91 88
             ];
92 89
 
93
-            try {
94
-                $this->client->indices()->create($params);
95
-            } catch(Exception $e) {
96
-                common_log(
97
-                    LOG_ERROR,
98
-                    "Unable to create index existing $this->index_name: $e->getMessage()"
99
-                );
100
-            }
90
+            $response = $this->client->indices()->create($params);
91
+
92
+            // TODO: Parse response, handle errors
101 93
         }
102 94
     }
103 95
 
@@ -162,17 +154,6 @@ class ElasticSearch extends SearchEngine
162 154
         $author = Profile::getKV('id', $notice->profile_id);
163 155
         $webfinger = $author->getAcctUri(false);
164 156
 
165
-        try {
166
-            $object_type = $notice->getObjectType();
167
-        } catch(NoObjectTypeException $e) {
168
-            common_log(
169
-                LOG_INFO,
170
-                "Notice $notice->getID() doesn't have an object_type"
171
-            );
172
-
173
-            $object_type = null;
174
-        }
175
-
176 157
         $params = [
177 158
             'index' => $this->index_name,
178 159
             'type' => $this->index_type,
@@ -180,8 +161,7 @@ class ElasticSearch extends SearchEngine
180 161
             'body' => [
181 162
                 'author' => $webfinger,
182 163
                 'text' => $notice->content,
183
-                'verb' => $notice->getVerb(true),
184
-                'type' => $object_type,
164
+                'type' => $notice->getVerb(true),
185 165
                 'created' => $notice->created
186 166
             ]
187 167
         ];
@@ -241,23 +221,19 @@ class ElasticSearch extends SearchEngine
241 221
         $hits = $response['hits']['hits'];
242 222
 
243 223
         if (count($hits) === 0) {
244
-            // No results
245
-            //
246
-            // Force empty result set because if we don't we end up
247
-            // displaying the most recent notices (no WHERE clause)
248
-            $this->target->whereAdd("1 = 2");
249
-        } else {
250
-            $ids = array();
251
-
252
-            foreach($hits as $hit) {
253
-                $ids[] = $hit['_id'];
254
-            }
224
+            return false;
225
+        }
255 226
 
256
-            $id_set = join(', ', $ids);
227
+        $ids = array();
257 228
 
258
-            $this->target->whereAdd("id in ($id_set)");
229
+        foreach($hits as $hit) {
230
+            $ids[] = $hit['_id'];
259 231
         }
260 232
 
233
+        $id_set = join(', ', $ids);
234
+
235
+        $this->target->whereAdd("id in ($id_set)");
236
+
261 237
         return true;
262 238
     }
263 239
 

Loading…
Cancel
Save