Esempio n. 1
0
        public static Document JsonToDocument(string type, string id, string userId, DateTime createdOnDate, JToken json, string source, FieldConfig config, bool storeSource = false)
        {
            var      objectMapper = new JsonObjectMapper();
            Document doc          = new Document();

            doc.Add(new Field(FIELD_TYPE, type, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(FIELD_ID, id, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(FIELD_USER_ID, userId, Field.Store.NO, Field.Index.NOT_ANALYZED));
            if (storeSource)
            {
                doc.Add(new Field(FIELD_SOURCE, source, Field.Store.YES, Field.Index.NO));
            }
            doc.Add(new NumericField(FIELD_TIMESTAMP, Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks));
            doc.Add(new NumericField(FIELD_CREATED_ON_DATE, Field.Store.NO, true).SetLongValue(createdOnDate.Ticks));
            objectMapper.AddJsonToDocument(json, doc, config);
            return(doc);
        }
Esempio n. 2
0
        public static Document JsonToDocument(string type, string id, string userId, DateTime createdOnDate, JToken json, string source, FieldConfig config, bool storeSource = false)
        {
            var      objectMapper = new JsonObjectMapper();
            Document doc          = new Document();

            doc.Add(new Field(FieldType, type, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(FieldId, id, Field.Store.YES, Field.Index.NOT_ANALYZED));
            doc.Add(new Field(FieldUserId, userId, Field.Store.NO, Field.Index.NOT_ANALYZED));
            if (storeSource)
            {
                doc.Add(new Field(FieldSource, source, Field.Store.YES, Field.Index.NO));
            }
            doc.Add(new NumericField(FieldTimestamp, Field.Store.YES, true).SetLongValue(DateTime.UtcNow.Ticks));
            doc.Add(new NumericField(FieldCreatedOnDate, Field.Store.NO, true).SetLongValue(createdOnDate.Ticks));
            objectMapper.AddJsonToDocument(json, doc, config);
            return(doc);
        }