コード例 #1
0
        public async Task <IHttpActionResult> PutSearchWords(int id, SearchWords searchWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != searchWords.id)
            {
                return(BadRequest());
            }

            db.Entry(searchWords).State = EntityState.Modified;

            try
            {
                await db.SaveChangesAsync();
            }
            catch (DbUpdateConcurrencyException)
            {
                if (!SearchWordsExists(id))
                {
                    return(NotFound());
                }
                else
                {
                    throw;
                }
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #2
0
        protected override async Task <Action <AsyncCodeActivityContext> > ExecuteAsync(AsyncCodeActivityContext context, CancellationToken cancellationToken)
        {
            // Object Container: Use objectContainer.Get<T>() to retrieve objects from the scope
            var objectContainer = context.GetFromContext <IObjectContainer>(TextApplicationScope.ParentContainerPropertyTag);

            // Inputs
            string inputText = objectContainer.Get <string>();

            // Inputs
            var searchWordsCol = SearchWords.Get(context);
            var displayLog     = DisplayLog;

            //Convert Collection to Array
            string[] searchWords = Utils.ConvertCollectionToArray(searchWordsCol);

            ///////////////////////////
            // Add execution logic HERE

            //Find Words in String
            double PercResults = Utils.FindWordsInString(inputText, searchWords, displayLog);

            ///////////////////////////

            // Outputs
            return((ctx) =>
            {
                Percentage.Set(ctx, PercResults);
            });
        }
コード例 #3
0
ファイル: Search.cs プロジェクト: moayyaed/YetaWF-Modules
 private async Task SearchPageAsync(SearchWords searchWords, PageDefinition page)
 {
     if (!searchWords.WantPage(page))
     {
         return;
     }
     if (await searchWords.SetUrlAsync(page.Url, page.PageSecurity, page.Title, page.Description, page.Created, page.Updated, page.IsAuthorized_View_Anonymous(), page.IsAuthorized_View_AnyUser()))
     {
         searchWords.AddKeywords(page.Keywords);
         foreach (var m in page.ModuleDefinitions)
         {
             Guid             modGuid = m.ModuleGuid;
             ModuleDefinition mod     = null;
             try {
                 mod = await ModuleDefinition.LoadAsync(m.ModuleGuid);
             } catch (Exception ex) {
                 Logging.AddErrorLog("An error occurred retrieving module {0} in page {1}", m.ModuleGuid, page.Url, ex);
             }
             if (mod != null)
             {
                 SearchModule(searchWords, mod);
             }
         }
         await searchWords.SaveAsync();
     }
 }
コード例 #4
0
        protected override void Seed(SearcherAPI.Models.SearcherContext context)
        {
            List <SearchWords> sWordList1 = new List <SearchWords>();
            List <SearchWords> sWordList2 = new List <SearchWords>();

            SearchWords sWord1 = new SearchWords()
            {
                SearchWord = "Lorem ipsum 1"
            };

            SearchWords sWord2 = new SearchWords()
            {
                SearchWord = "jibberish"
            };
            SearchWords sWord3 = new SearchWords()
            {
                SearchWord = "Lorem ipsum 2"
            };

            SearchWords sWord4 = new SearchWords()
            {
                SearchWord = "Sludder"
            };

            context.SearchWords.Add(sWord1);
            context.SearchWords.Add(sWord2);
            context.SearchWords.Add(sWord3);
            context.SearchWords.Add(sWord4);

            sWordList1.Add(sWord1);
            sWordList1.Add(sWord2);
            sWordList2.Add(sWord3);
            sWordList2.Add(sWord4);



            Texts text1 = new Texts()
            {
                title = "Lorem ipsum no. 1",
                text  = "Lorem ipsum dolor sit amet elementum. A tempus vestibulum dapibus " +
                        "id morbi consequat faucibus libero cursus nunc malesuada. " +
                        "Vulputate ac et. Mi dictum quas. Laoreet aenean risus lacus sed sapien.",
                SearchWords = sWordList1
            };

            Texts text2 = new Texts()
            {
                title = "Lorem ipsum no. 2",
                text  = "Leo et sollicitudin. Eu nunc lacus. Mauris elementum suscipit " +
                        "integer augue sed fringilla lacus a. Scelerisque venenatis at mollis " +
                        "eros dolor. Ut ut tellus nec arcu sodales tellus massa sem.",
                SearchWords = sWordList2
            };

            context.Texts.Add(text1);
            context.Texts.Add(text2);
        }
コード例 #5
0
        public Task <IHttpActionResult> SearchTextsWithString(SearchWords searchWord)
        {
            return(Task.Run(() =>
            {
                var logic = new Searcher();
                var texts = logic.SearchTextsWithString(searchWord.SearchWord);

                return (IHttpActionResult)Ok(texts);
            }));
        }
コード例 #6
0
        public async Task <IHttpActionResult> GetSearchWords(int id)
        {
            SearchWords searchWords = await db.SearchWords.Include("Texts").FirstOrDefaultAsync(x => x.id == id);

            if (searchWords == null)
            {
                return(NotFound());
            }

            return(Ok(searchWords));
        }
コード例 #7
0
        public async Task <IHttpActionResult> PostSearchWords(SearchWords searchWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            db.SearchWords.Add(searchWords);
            await db.SaveChangesAsync();

            return(CreatedAtRoute("DefaultApi", new { id = searchWords.id }, searchWords));
        }
コード例 #8
0
        public async Task <IHttpActionResult> DeleteSearchWords(int id)
        {
            SearchWords searchWords = await db.SearchWords.FindAsync(id);

            if (searchWords == null)
            {
                return(NotFound());
            }

            db.SearchWords.Remove(searchWords);
            await db.SaveChangesAsync();

            return(Ok(searchWords));
        }
コード例 #9
0
        /// <summary>
        /// Indexes a searchword, finds all texts containig it and adds
        /// a connection to database between seachword and text.
        /// </summary>
        /// <param name="searchword">
        /// Provided searchword
        /// </param>
        /// <returns>
        /// boolean with value depending if indexing was succesfull
        /// </returns>
        public bool IndexSearchWord(SearchWords searchword)
        {
            try
            {
                using (var db = new SearcherContext())
                {
                    //List of texts containing searchword
                    List <Texts> texts = db.Texts.Where(t => t.text.Contains(searchword.SearchWord))
                                         .Include(t => t.SearchWords)
                                         .ToList();
                    foreach (var text in texts)
                    {
                        bool update = true;
                        //For each loop checks if there is already such searchword for this text
                        foreach (var searchWordInText in text.SearchWords)
                        {
                            if (searchWordInText.SearchWord.Contains(searchword.SearchWord))
                            {
                                update = false;
                            }
                        }
                        //If there is no such search word for text, it is indexed
                        if (update)
                        {
                            //Fiding the actual searchword from table
                            SearchWords existingSearchword =
                                db.SearchWords.FirstOrDefault(s => s.SearchWord.Equals(searchword.SearchWord));
                            if (existingSearchword != null)
                            {
                                text.SearchWords.Add(existingSearchword);
                                db.Entry(text).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                            }
                            else
                            {
                                text.SearchWords.Add(searchword);
                                db.Entry(text).State = System.Data.Entity.EntityState.Modified;
                                db.SaveChanges();
                            }
                        }
                    }
                }

                return(true);
            }
            catch (Exception)
            {
                return(false);
            }
        }
コード例 #10
0
ファイル: Search.cs プロジェクト: moayyaed/YetaWF-Modules
 private void SearchModule(SearchWords searchWords, ModuleDefinition mod)
 {
     if (mod.WantSearch)
     {
         if (searchWords.SetModule(mod.IsAuthorized_View_Anonymous(), mod.IsAuthorized_View_AnyUser()))
         {
             if (mod.ShowTitle)
             {
                 searchWords.AddTitle(mod.Title);
             }
             searchWords.AddContent(mod.Description);
             mod.CustomSearch(searchWords);
             searchWords.ClearModule();
         }
     }
 }
コード例 #11
0
 public Task <IHttpActionResult> IndexSearchWord(SearchWords searchWord)
 {
     return(Task.Run(() =>
     {
         var logic = new Indexer();
         bool result = logic.IndexSearchWord(searchWord);
         if (result)
         {
             return (IHttpActionResult)Ok(result);
         }
         else
         {
             return BadRequest(result.ToString());
         }
     }));
 }
コード例 #12
0
        public async Task <IHttpActionResult> GetSearchWords(int id)
        {
            var url = Helper.GetNextUrl();

            HttpResponseMessage response = await Client.GetAsync(url + "api/SearchWords/" + id);

            if (response.IsSuccessStatusCode)
            {
                SearchWords searchWords = await response.Content.ReadAsAsync <SearchWords>();

                if (searchWords == null)
                {
                    return(NotFound());
                }
                return(Ok(searchWords));
            }
            return(BadRequest());
        }
コード例 #13
0
        public async Task <IHttpActionResult> PostSearchWords(SearchWords searchWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            var url = Helper.GetNextUrl();

            HttpResponseMessage response = Client.PostAsJsonAsync(url + "api/searchWords/", searchWords).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Ok(await response.Content.ReadAsAsync <SearchWords>()));
            }

            return(BadRequest("haha"));
        }
コード例 #14
0
        private void btn_s_Click(object sender, EventArgs e)
        {
            int    indextmp = -1;
            string swordtmp = _caseSensitive ? SearchWords.ToLower() : SearchWords;

            if (_sequentialSearch)
            {
                if (_sloc == _owner.txtRtb.Text.Length - 1)
                {
                    if (UI.Forms.MessageBox.Show(_f, "已经搜索至最后,是否重新从头开始搜索?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        _sloc = 0;
                    }
                }
                indextmp = _owner.txtRtb.Text.IndexOf(swordtmp, _sloc + 1, _owner.txtRtb.Text.Length - _sloc - 1);
            }
            else
            {
                if (_sloc == 0)
                {
                    if (UI.Forms.MessageBox.Show(_f, "已经搜索至最前,是否重新从最后开始搜索?", "", MessageBoxButtons.YesNo) == DialogResult.Yes)
                    {
                        _sloc = _owner.txtRtb.Text.Length - 1;
                    }
                }
                indextmp = _owner.txtRtb.Text.LastIndexOf(swordtmp, _sloc - 1, _sloc - 1);
            }

            if (indextmp == -1)
            {
                string inf = "未搜索到任何内容";
                UI.Forms.MessageBox.Show(_f, inf, "", MessageBoxButtons.OK);
            }
            else
            {
                _sloc = indextmp;
                _owner.txtRtb.SelectionStart  = _sloc;
                _owner.txtRtb.SelectionLength = SearchWords.Length;
            }
        }
コード例 #15
0
        public async Task <IHttpActionResult> PutSearchWords(int id, SearchWords searchWords)
        {
            if (!ModelState.IsValid)
            {
                return(BadRequest(ModelState));
            }

            if (id != searchWords.id)
            {
                return(BadRequest());
            }

            var url = Helper.GetNextUrl();

            HttpResponseMessage response = Client.PutAsJsonAsync(url + "api/searchWords/" + id, searchWords).Result;

            if (response.IsSuccessStatusCode)
            {
                return(Ok(await response.Content.ReadAsAsync <SearchWords>()));
            }

            return(StatusCode(HttpStatusCode.NoContent));
        }
コード例 #16
0
ファイル: ReplacePanel.cs プロジェクト: lonelyong/NgNet
        private void soWordsTextBox_TextChanged(object sender, EventArgs e)
        {
            bool tmp = string.IsNullOrEmpty(_owner.txtRtb.Text) || string.IsNullOrEmpty(_searchWordsTextBox.Text);

            _searchBtn.Enabled = !tmp;

            if (caseSensitive)
            {
                tmp = tmp || string.IsNullOrEmpty(_replaceDataTextBox.Text) || _owner.txtRtb.SelectedText != SearchWords;
            }
            else
            {
                tmp = tmp || string.IsNullOrEmpty(_replaceDataTextBox.Text) || _owner.txtRtb.SelectedText.ToLower() != SearchWords.ToLower();
            }
            _replaceBtn.Enabled    = !tmp;
            _replaceAllBtn.Enabled = !tmp;
        }
コード例 #17
0
 public void AddSearchString(string inString)
 {
     SearchWords.Add(inString);
     OnSearchWordsChanged?.Invoke(this, null);
 }
コード例 #18
0
 /// <summary>
 /// Adds the search string.
 /// </summary>
 /// <param name="inString">The in string.</param>
 public void AddSearchString(String inString)
 {
     SearchWords.Add(inString);
     Update();
 }
コード例 #19
0
 private void UpdateRegex(object sender, EventArgs e)
 {
     RegularExpression = SearchWords.ToRegex();
 }
コード例 #20
0
ファイル: Search.cs プロジェクト: moayyaed/YetaWF-Modules
        public async Task SearchSiteAsync(bool slow)
        {
            SearchConfigData searchConfig = await SearchConfigDataProvider.GetConfigAsync();

            DateTime searchStarted = DateTime.UtcNow; // once we have all new keywords, delete all keywords that were added before this date/time

            using (SearchDataProvider searchDP = new SearchDataProvider()) {
                // Search all generated pages (unique modules or classes, like data providers)
                DynamicUrlsImpl dynamicUrls = new DynamicUrlsImpl();
                List <Type>     types       = dynamicUrls.GetDynamicUrlTypes();
                // search types that generate dynamic urls
                foreach (Type type in types)
                {
#if DEBUG
                    //                  if (type.Name != "FileDocumentDisplayModule") continue;//used for debugging
#endif
                    ISearchDynamicUrls iSearch = Activator.CreateInstance(type) as ISearchDynamicUrls;
                    if (iSearch != null)
                    {
                        try {
                            SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                            await iSearch.KeywordsForDynamicUrlsAsync(searchWords);

                            if (slow)
                            {
                                Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                            }
                        } catch (Exception exc) {
                            Logging.AddErrorLog("KeywordsForDynamicUrls failed for {0}", type.FullName, exc);
                        }
                    }
                }

                // search all designed modules that have dynamic urls
                foreach (DesignedModule desMod in await DesignedModules.LoadDesignedModulesAsync())
                {
                    try {
                        ModuleDefinition mod = await ModuleDefinition.LoadAsync(desMod.ModuleGuid, AllowNone : true);

                        if (mod != null && types.Contains(mod.GetType()) && mod.WantSearch)
                        {
                            ISearchDynamicUrls iSearch = mod as ISearchDynamicUrls;
                            if (iSearch != null)
                            {
                                SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                                await iSearch.KeywordsForDynamicUrlsAsync(searchWords);

                                if (slow)
                                {
                                    Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                                }
                            }
                        }
                    } catch (Exception exc) {
                        Logging.AddErrorLog("KeywordsForDynamicUrls failed for module {0}", desMod.ModuleGuid, exc);
                    }
                }

                // Search all designed pages and extract keywords
                List <Guid> pages = await PageDefinition.GetDesignedGuidsAsync();

                foreach (Guid pageGuid in pages)
                {
                    PageDefinition page = await PageDefinition.LoadAsync(pageGuid);

                    if (page != null)
                    {
                        SearchWords searchWords = new SearchWords(searchConfig, searchDP, searchStarted);
                        await SearchPageAsync(searchWords, page);

                        if (slow)
                        {
                            Thread.Sleep(500);// delay a bit (slow can only be used by scheduler items)
                        }
                    }
                }

                // Remove old keywords
                await searchDP.RemoveOldItemsAsync(searchStarted);
            }
        }
コード例 #21
0
ファイル: MainModel.cs プロジェクト: gareth-reid/RockMelon2
 public bool Search(string pageSearchWords)
 {
     return(!String.IsNullOrEmpty(SearchWords) && pageSearchWords.ToLower().Contains(SearchWords.ToLower()));
 }
コード例 #22
0
ファイル: search.aspx.cs プロジェクト: DragonZX/chmprocessor
    protected void Page_Load(object sender, EventArgs e)
    {
        DateTime start = DateTime.Now;

        txtResult.Text = "";
        string queryText = Request["q"];
        int    startPage = 0;

        if (Request["s"] != null)
        {
            try { startPage = Int32.Parse(Request["s"]); }
            catch { }
        }
        ;

        if (queryText != null)
        {
            char[]   tokens = { ' ' };
            string[] words  = queryText.Split(tokens);

            string      webDirectory = Path.GetDirectoryName(Request.PhysicalPath);
            string      pathDB       = webDirectory + Path.DirectorySeparatorChar + "fullsearchdb.db3";
            WebIndex    idx          = null;
            ArrayList   results      = null;
            SearchWords searchWords  = null;
            try
            {
                idx = new WebIndex();
                idx.Connect(pathDB);
                //results = idx.Search(words);
                searchWords = idx.PrepareRealWords(words);
                if (searchWords == null)
                {
                    // Some word not found:
                    results = new ArrayList(0);
                }
                else
                {
                    results = idx.Search(searchWords);
                }
            }
            finally
            {
                if (idx != null)
                {
                    idx.Disconnect();
                }
            }

            //ArrayList normalizedWords = WebIndex.NormalizeWordsSet(words);

            string textFilesDir = webDirectory + Path.DirectorySeparatorChar + "textFiles";

            int startResult = startPage * NRESULTSBYPAGE;
            int lastResult  = (startPage + 1) * NRESULTSBYPAGE;
            if (lastResult > results.Count)
            {
                lastResult = results.Count;
            }

            txtSearchText.Text = "";
            foreach (string word in words)
            {
                txtSearchText.Text += word + " ";
            }

            txtShowResults.Text  = (startResult + 1) + " - " + lastResult;
            txtTotalResults.Text = results.Count.ToString();

            txtResult.Text += "<p>";
            for (int i = startResult; i < lastResult; i++)
            {
                Result result = (Result)results[i];
                txtResult.Text += result.GoogleTextFormat(textFilesDir, searchWords) + "\n";
            }
            txtResult.Text += "</p>";

            if (results.Count > NRESULTSBYPAGE)
            {
                int nPages = results.Count / NRESULTSBYPAGE;
                if ((results.Count % NRESULTSBYPAGE) > 0)
                {
                    nPages++;
                }

                if (startPage != 0)
                {
                    lnkPrevious.NavigateUrl = HRef(queryText, startPage - 1);
                }
                else
                {
                    lnkPrevious.Visible = false;
                }

                for (int i = 0; i < nPages; i++)
                {
                    if (startPage != i)
                    {
                        int number = i + 1;
                        txtResultLinks.Text += " " + Link(queryText, i, number.ToString());
                    }
                    else
                    {
                        txtResultLinks.Text += " <font color=\"red\">" + (i + 1) + "</font>";
                    }
                }
                if (startPage != (nPages - 1))
                {
                    lnkNext.NavigateUrl = HRef(queryText, startPage + 1);
                }
                else
                {
                    lnkNext.Visible = false;
                }
            }
            else
            {
                txtMoreResults.Visible = false;
                lnkPrevious.Visible    = false;
                lnkNext.Visible        = false;
            }
        }
        else
        {
            txtSearchText.Text     = "";
            txtShowResults.Text    = "0 - 0";
            txtTotalResults.Text   = "0";
            txtMoreResults.Visible = false;
            lnkPrevious.Visible    = false;
            lnkNext.Visible        = false;
        }

        DateTime end     = DateTime.Now;
        TimeSpan span    = end.Subtract(start);
        double   roundMs = Math.Round(span.TotalMilliseconds, 2);

        txtMiliseconds.Text = roundMs.ToString();
    }
コード例 #23
0
        private void Seed()
        {
            using (var context = new TaskDbContext(contextOptions, configuration, DataBaseFlags.Test))
            {
                context.Database.EnsureDeleted();
                context.Database.EnsureCreated();

                #region InitTextTask
                var oneTextTask = new TextTask()
                {
                    Id               = new Guid(),
                    StartTime        = DateTime.Now.AddDays(-1),
                    EndTime          = DateTime.Now.AddHours(4),
                    CountOfRepeating = 30
                };
                var twoTextTask = new TextTask()
                {
                    Id               = new Guid(),
                    StartTime        = DateTime.Now,
                    EndTime          = DateTime.Now.AddDays(1),
                    CountOfRepeating = 40
                };
                _textTask = new List <TextTask>()
                {
                    oneTextTask, twoTextTask
                };
                context.TextTask.AddRange(oneTextTask, twoTextTask);
                #endregion

                #region InitSearxhWords
                var oneSearchWords = new SearchWords()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[0].Id,
                    Word   = "a"
                };
                var twoSearchWords = new SearchWords()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[0].Id,
                    Word   = "b"
                };
                var threeSearchWords = new SearchWords()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[1].Id,
                    Word   = "а"
                };
                var fourSearchWords = new SearchWords()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[1].Id,
                    Word   = "б"
                };
                _searchWords = new List <SearchWords>()
                {
                    oneSearchWords, twoSearchWords, threeSearchWords, fourSearchWords
                };
                context.SearchWords.AddRange(oneSearchWords, twoSearchWords, threeSearchWords, fourSearchWords);
                #endregion

                #region InitTextTaskResult
                var oneTextTaskResult_1 = new TextTaskResult()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[0].Id,
                    IdText = new Guid("65BC3B85-806F-493B-ADBA-E13E3C935A60"),
                    IdWord = _searchWords[0].Id,
                    Count  = 1
                };
                var oneTextTaskResult_2 = new TextTaskResult()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[0].Id,
                    IdText = new Guid("65BC3B85-806F-493B-ADBA-E13E3C935A60"),
                    IdWord = _searchWords[1].Id,
                    Count  = 21
                };
                var twoTextTaskResult_1 = new TextTaskResult()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[1].Id,
                    IdText = new Guid("65BC3B85-806F-493B-ADBA-E13E3C935A60"),
                    IdWord = _searchWords[2].Id,
                    Count  = 7
                };
                var twoTextTaskResult_2 = new TextTaskResult()
                {
                    Id     = new Guid(),
                    IdTask = _textTask[1].Id,
                    IdText = new Guid("65BC3B85-806F-493B-ADBA-E13E3C935A60"),
                    IdWord = _searchWords[3].Id,
                    Count  = 8
                };
                _textTaskResult = new List <TextTaskResult>()
                {
                    oneTextTaskResult_1, oneTextTaskResult_2, twoTextTaskResult_1, twoTextTaskResult_2
                };
                context.TextTaskResult.AddRange(oneTextTaskResult_1, oneTextTaskResult_2, twoTextTaskResult_1, twoTextTaskResult_2);
                #endregion

                context.SaveChanges();
            }
        }