Exemple #1
0
 ThrowIfNullEmptyOrWhiteSpace(relativePath, nameof(relativePath));
Exemple #2
0
 var result = await GetAsync(relativePath, parameters);
        private static void IndexFile(IndexWriter writer, FileInfo file)
        {
            if (!file.Exists)
            {
                return;
            }
            Lucene.Net.Documents.Document doc = new Lucene.Net.Documents.Document();
            string     path                     = file.FullName;
            string     folder                   = file.DirectoryName;
            string     final_folder             = Regex.Replace(folder, "temp", " ");
            TextReader readFile                 = new StreamReader(path);
            string     temp_fileName            = file.Name;
            string     fileName                 = Regex.Replace(temp_fileName, ".txt", "");
            string     fileNameWithoutExtension = Path.GetFileNameWithoutExtension(fileName);
            string     test_content             = "";
            string     check_extention          = Path.GetExtension(temp_fileName);
            var        content                  = System.IO.File.ReadAllText(path);
            var        test_content1            = string.Empty;
            string     metaContent              = string.Empty;
            string     temp_relativePath        = string.Empty;
            string     final_relativePath       = string.Empty;

            if (check_extention == ".cshtml" || check_extention == ".aspx" || check_extention == ".html" || check_extention == ".php")
            {
                relativePath relativepath = new relativePath(path);
                temp_relativePath  = relativepath.getRelativePath(folder);
                final_relativePath = Regex.Replace(temp_relativePath, ".txt", "");
                if (content != null)
                {
                    string plainText             = Regex.Replace(content, @"(<script\b[^>]*>(.*?)<\/script>)|(<style\b[^>]*>(.*?)<\/style>)", "", RegexOptions.Singleline); //remove javascript and css
                    string plainTextfromPageTemp = Regex.Replace(plainText, "<[^>]+?>|&\\w+;", "");                                                                         //remove HTML
                    if (check_extention == ".cshtml")
                    {
                        string temp1PlainTextfromCSHTML = Regex.Replace(plainTextfromPageTemp, @"[@]\{([^\)]+)\}", ""); //remove all text betwwen @{ }
                        string temp2PlainTextfromCSHTML = Regex.Replace(temp1PlainTextfromCSHTML, @"[@].*", "");        //remove line starting with @
                        plainTextfromPageTemp = Regex.Replace(temp2PlainTextfromCSHTML, @"\{([^\)]+)\}", "");           //remove all text betwwen { }
                    }
                    string plainTextfromPage1 = Regex.Replace(plainTextfromPageTemp, @"(\t|\n|\r)", " ");               //remove blank lines
                    string plainTextfromPage  = Regex.Replace(plainTextfromPage1, @"[ ]{2,}", " ");                     //remove unwanted spaces
                    test_content = test_content + " " + plainTextfromPage;
                    //collecting contents of meta tags
                    metaContent = GetMetaTags(path);
                }
            }
            else
            {
                //Assigning original path
                pathList pathlist   = new pathList();
                string[] listofpath = pathlist.readPath();
                foreach (string pathlists in listofpath)
                {
                    if (pathlists != string.Empty)
                    {
                        DirectoryInfo indexInfo    = new DirectoryInfo(pathlists);
                        string        fileNameOnly = indexInfo.Name;
                        if (fileName == fileNameOnly)
                        {
                            relativePath relativepath = new relativePath(pathlists);
                            final_relativePath = relativepath.getRelativePath(folder);
                            break;
                        }
                    }
                }
                //
                test_content = test_content + " " + content;
            }
            //doc.Add(new Field("contents", readFile));
            doc.Add(new Field("prevewContent", test_content, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.Add(new Field("URL", final_relativePath, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.Add(new Field("filename", fileName, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.Add(new Field("fileNameWithoutExtension", fileNameWithoutExtension, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            doc.Add(new Field("metaTag", metaContent, Field.Store.YES, Field.Index.ANALYZED, Field.TermVector.YES));
            writer.AddDocument(doc);
            writer.Optimize();
            writer.Flush(true, true, true);
        }