Special characters

69 views
Skip to first unread message

Andre Hegge

unread,
Aug 20, 2012, 5:51:28 AM8/20/12
to rav...@googlegroups.com
Hello! We scrape texts from html documents and put them into Raven. Then, we use javascript to retrieve and display the texts in other html documents.

A problem we have is that Raven adds \r\n\t and \" to the text strings. This is hardly expected behaviour. Why is this and is there an easy fix?

Oren Eini (Ayende Rahien)

unread,
Aug 20, 2012, 5:55:42 AM8/20/12
to rav...@googlegroups.com
You need to parse the text as JSON.
In JS, you can do that using JSON.Stringify()

Starfish

unread,
Aug 22, 2012, 7:01:39 AM8/22/12
to rav...@googlegroups.com
Hi! We already do this. The code:

var str = "<div class='result'>"
+ "<div class='result-title'>" + JSON.stringify(json.Messages[i].Author) + "</div>"
+ "<div class='result-date'>Updated " + stringifyTimestamp(JSON.stringify(json.Messages[i].Created).substring(7, 20)) + "</div>"
            + "<div class='result-text'/>" + JSON.stringify(json.Messages[i].Text) + "</div>"
            + "<a href='http://example.com'><div class='result-link'>" + JSON.stringify(json.Messages[i].ExternalId) + "</div></a>"
            + "</div>";
        result.innerHTML += str;

Oren Eini (Ayende Rahien)

unread,
Aug 22, 2012, 7:04:50 AM8/22/12
to rav...@googlegroups.com
Can you show a full sample so we can reproduce?

Starfish

unread,
Aug 22, 2012, 7:21:51 AM8/22/12
to rav...@googlegroups.com
One moment, i need to compile it.

Starfish

unread,
Aug 22, 2012, 8:34:31 AM8/22/12
to rav...@googlegroups.com
The usage is:

sample.html?query=hello

It uses an old version of our api.
sample.html

Oren Eini (Ayende Rahien)

unread,
Aug 22, 2012, 8:44:37 AM8/22/12
to rav...@googlegroups.com
This is your own output from your own API.
What is the association to RavenDB?

Starfish

unread,
Aug 22, 2012, 10:54:10 AM8/22/12
to rav...@googlegroups.com
Yes, sorry about that. 

The api just serializes a Raven response though:

var q = session.Advanced.LuceneQuery<Message>(IndxName)
//.Statistics(out stats)
.Search(x => x.Text, query);
//.AndAlso()..WhereLessThanOrEqual("Created", DateTime.UtcNow.ToLongTimeString())
if (category != "") q = q.AndAlso().WhereEquals("CategoryId", category);
if (forum != "") q = q.AndAlso().WhereEquals("ForumId", forum);
if (author != "") q = q.AndAlso().WhereEquals("Author", author);
q = q.Take(12);
var q1 = q.ToList().OrderBy(s => s.Created).Reverse();
var qres = q.ToArray(); // do actual query

var jsonSerializer = new System.Web.Script.Serialization.JavaScriptSerializer();
string json = jsonSerializer.Serialize(qres);

Oren Eini (Ayende Rahien)

unread,
Aug 22, 2012, 11:16:17 AM8/22/12
to rav...@googlegroups.com
That has nothing to do with RavenDB then, you are getting the value back.
Then you serialize it yourself.
Reply all
Reply to author
Forward
0 new messages