[Groonga-commit] nroonga/norema [master] Keep index and type in item object

Zurück zum Archiv-Index

Yoji SHIDARA null+****@clear*****
Tue Aug 21 14:03:15 JST 2012


Yoji SHIDARA	2012-08-21 14:03:15 +0900 (Tue, 21 Aug 2012)

  New Revision: 16f662a3a22ef6aaae747bf70702d6a051342f01
  https://github.com/nroonga/norema/commit/16f662a3a22ef6aaae747bf70702d6a051342f01

  Log:
    Keep index and type in item object

  Modified files:
    tools/convert.js

  Modified: tools/convert.js (+10 -3)
===================================================================
--- tools/convert.js    2012-08-15 17:55:25 +0900 (0c2256a)
+++ tools/convert.js    2012-08-21 14:03:15 +0900 (562b867)
@@ -31,6 +31,8 @@ function parse(doc, context) {
   context = context || {};
   context.items = context.items || [];
   context.path = context.path || [];
+  context.type = context.type || null;
+  context.index = context.index || 0;
 
   if (title) {
     context.title = title;
@@ -39,19 +41,24 @@ function parse(doc, context) {
   if (doc.desc) {
     item.desc = doc.desc;
     item.title = context.title;
+    item.type = context.type;
+    item.index = context.index;
     item.path = context.path.map(function(item) {
       return item.title;
     }).filter(function(title) {
       return title;
     });
     context.items.push(item);
+    context.index++;
   }
 
   context.path.push(item);
   for (var type in doc) {
     if (doc[type] instanceof Array) {
       doc[type].forEach(function(subdoc) {
+        context.type = type;
         parse(subdoc, context);
+        context.type = null;
       });
     }
   }
@@ -63,11 +70,11 @@ function parse(doc, context) {
 function toSdf(records) {
   var version = (new Date()).getTime();
 
-  return records.map(function(record, index) {
-    console.log(index, record.path, record.title);
+  return records.map(function(record) {
+    console.log(record.index, record.type, record.path, record.title);
     return {
       type: 'add',
-      id: 'doc_' + index,
+      id: 'doc_' + record.index,
       version: version,
       lang: 'en',
       fields: record
-------------- next part --------------
HTML����������������������������...
Download 



More information about the Groonga-commit mailing list
Zurück zum Archiv-Index