forked from kurokikaze/node-search-engine
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathxmlpipe2.js
More file actions
75 lines (56 loc) · 2.03 KB
/
xmlpipe2.js
File metadata and controls
75 lines (56 loc) · 2.03 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
var couch = require('./node-couch').CouchDB,
libxml = require('./libxmljs'),
settings = require('./settings'),
sys = require('sys');
var db = couch.db(settings.couchbase, settings.couchhost);
var doc_id = 1;
var process_document = function (docs) {
if (docs.length > 0) {
doc_id++;
var document = docs.pop();
db.openDoc(document.id,{
'success': function(page) {
sys.puts('<sphinx:document id="' + parseInt(page._id) + '">');
sys.puts('<subject>');
if (page.title) {
sys.puts(page.title.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"));
} else {
sys.puts('No title');
}
sys.puts('</subject>');
sys.puts('<content>');
if (page.text) {
sys.puts(page.text.replace(/&/g, "&").replace(/</g, "<").replace(/>/g, ">"));
}
sys.puts('</content>');
if (page.url) {
sys.puts('<url>' + page.url + '</url>');
} else {
sys.puts('<url />');
}
sys.puts('</sphinx:document>');
process_document(docs);
},
'error':function (e) {
sys.puts('Error getting doc: ' + sys.inspect(e));
}
});
} else {
sys.puts('</sphinx:docset>');
}
};
db.allDocs({
'success': function(docs) {
sys.puts('<' + '?xml version="1.0" encoding="utf-8"?>');
sys.puts('<sphinx:docset>');
sys.puts('<sphinx:schema>');
sys.puts(' <sphinx:field name="subject" />');
sys.puts(' <sphinx:field name="content" />');
sys.puts(' <sphinx:field name="url" />');
sys.puts('</sphinx:schema>');
process_document(docs.rows);
},
'error': function(errorResponse) {
sys.puts('Error getting all docs: ' + JSON.stringify(errorResponse.reason));
}
});