Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
26 changes: 21 additions & 5 deletions lib/searchresult.js
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ SearchResult.prototype.toXML = function toXML(options) {
else
length = (max > this.documents.length) ? this.documents.length : max;
}
else
length = (!ids) ? this.documents.length : ids.length

var result = SearchResult.XML_OPEN;

Expand All @@ -97,10 +99,10 @@ SearchResult.prototype.toXML = function toXML(options) {
doc = (ids) ? this.documentHash[ids[i]] : this.documents[i];

if(doc) {
result += "<document id=\"" +doc.id+ "\">";
result += "<snippet>" +doc.snippet+ "</snippet>";
result += "<url>" +doc.url+ "</url>";
result += "<title>" +doc.title+ "</title>";
result += "<document id=\"" + escape(doc.id) + "\">";
result += "<snippet>" + escape(doc.snippet) + "</snippet>";
result += "<url>" + escape(doc.url) + "</url>";
result += "<title>" + escape(doc.title) + "</title>";
result += "</document>";
}
}
Expand Down Expand Up @@ -155,6 +157,20 @@ SearchResult.XML_QUERY_OPEN = "<query>";
SearchResult.XML_QUERY_CLOSE = "</query>";
SearchResult.XML_CLOSE = "</searchresult>";

function escape(txt)
{

if (typeof txt == 'string')
{
return txt.replace(/&/g, '&amp;')
.replace(/</g, '&lt;')
.replace(/>/g, '&gt;')
.replace(/"/g, '&quot;');
}
else
return txt;
}

function serialize(_obj)
{
switch (typeof _obj)
Expand Down Expand Up @@ -192,4 +208,4 @@ function serialize(_obj)
return 'UNKNOWN';
break;
}
};
};
6 changes: 4 additions & 2 deletions lib/server.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,10 @@ function validateAlgorithm(algorithm) {
* source — By Source Clustering
*/

var validAlgorithms = ['lingo', 'stc', 'kmeans'];

algorithm = algorithm.toLowerCase();
if(algorithm!="lingo" || algorithm!="stc" || algorithm!="kmeans")
if(validAlgorithms.indexOf(algorithm) == -1)
algorithm = "lingo";
return algorithm;
};
Expand Down Expand Up @@ -167,4 +169,4 @@ DocumentClusteringServer.prototype.makeRequest = function makeRequest(search_res

req.write(data);
req.end();
};
};