Пример #1
0
        public void FileIndexing(List <string> words, int docId)
        {
            using (indexFiledbContext db = new indexFiledbContext())
            {
                foreach (string word in words)
                {
                    if (db.Words.Where(item => item.Content == word.ToLower()).Count() == 0)
                    {
                        Word wordDB = new Word();
                        wordDB.Content = word;

                        db.Words.Add(wordDB);
                        db.SaveChanges();
                    }
                    Inverse inverse = new Inverse();
                    inverse.DocId  = docId;
                    inverse.WordId = db.Words.Where(p => p.Content == word).Single().WordId;

                    db.Inverse.Add(inverse);
                    db.SaveChanges();
                }
            }
        }
Пример #2
0
        public ActionResult Upload(List <IFormFile> upload)
        {
            foreach (IFormFile uploadFile in upload)
            {
                int    id;
                string strFileExtension = Path.GetExtension(uploadFile.FileName);
                string name             = Path.GetFileNameWithoutExtension(uploadFile.FileName);

                using (indexFiledbContext db = new indexFiledbContext())
                {
                    Document document = new Document();
                    document.Name = Path.GetFileNameWithoutExtension(uploadFile.FileName);
                    document.Type = Path.GetExtension(uploadFile.FileName);

                    if (db.Documents.Where(p => p.Name == document.Name && p.Type == document.Type).Count() == 0)
                    {
                        db.Documents.Add(document);
                        db.SaveChanges();

                        id = db.Documents.Where(p => p.Name == document.Name && p.Type == document.Type).Single().DocId;
                    }
                    else
                    {
                        ModelState.AddModelError(uploadFile.FileName, "file already downloaded");
                        return(BadRequest(ModelState));
                    }
                }
                byte[] fileDoc = null;
                using (var binaryReader = new BinaryReader(uploadFile.OpenReadStream()))
                {
                    fileDoc = binaryReader.ReadBytes((int)uploadFile.Length);
                }

                List <string> words = TextSeparation(fileDoc);
                FileIndexing(words, id);
            }
            return(Created("", "indexing successful"));
        }