Esempio n. 1
0
        private void AddDocumentToIndex(IndexDocument doc)
        {
            // add fields
            foreach (var key in doc.Keys)
            {
                SaveField(key);
            }

            using (var cn = GetConnection())
            {
                var sqlIndexValue =
                    "INSERT OR REPLACE INTO IndexContent (doc, field, value) VALUES (@doc, (select id from IndexField where name = @name), @value);";

                // get doc by id; delete if exists
                var docId = cn.ExecuteScalar <int>(Resources.Resources.GetDocumentById, new { value = doc.KeyValue });
                if (docId > 0)
                {
                    cn.Execute(Resources.Resources.DeleteDocument, new { id = docId });
                }

                // insert doc
                docId = cn.ExecuteScalar <int>(Resources.Resources.InsertDocument,
                                               new { keyField = doc.KeyField, keyValue = doc.KeyValue });

                // insert fields
                foreach (var key in doc.Keys)
                {
                    cn.Execute(sqlIndexValue, new { doc = docId, name = key, value = doc[key] });
                }
            }
        }
Esempio n. 2
0
        internal override void IndexFile(string fullFileName, string folder)
        {
            var fi      = new FileInfo(fullFileName);
            var content = File.ReadAllText(fullFileName);
            var date    = fi.LastWriteTime.ToString("yyyyMMdd HH:mm:ss.fffff");
            var path    = fullFileName.Replace(folder, "");

            var doc = new IndexDocument();

            doc.AddField("path", path);
            doc.AddField("date", date);
            doc.AddField("content", content);
            doc.SetKey("path");

            AddDocumentToIndex(doc);
        }