예제 #1
0
        public ActionResult CreateFullTextIndex()
        {
            KeywordSearch.CreateFullTextIndex <Models.Page>();
            KeywordSearch.CreateFullTextIndex <Models.Event>();
            KeywordSearch.CreateFullTextIndex <Models.News>();

            return(Content("Done"));
        }
예제 #2
0
        public IActionResult Get(string keyword)
        {
            try
            {
                //如果keyword为空,不做要求
                if (keyword == null)
                {
                    keyword = "";
                }

                var pediaList = from pedia in _context.Encyclopedia
                                where KeywordSearch.ContainsKeywords(pedia.title + " " + pedia.content, keyword)
                                orderby pedia.post_date descending
                                select pedia;

                if (pediaList.Count() == 0)
                {
                    throw (new Exception("没有找到满足条件的数据"));
                }
                List <EncyclopediaForShow> showList = new List <EncyclopediaForShow>();
                string contract_content             = new string("");
                foreach (var nwsrow in pediaList)
                {
                    if (nwsrow.content.Count() > 50)
                    {
                        contract_content = nwsrow.content.Substring(0, 50) + "...";
                    }
                    else
                    {
                        contract_content = nwsrow.content;
                    }
                    EncyclopediaForShow temp = new EncyclopediaForShow()
                    {
                        author_name = nwsrow.author_name,
                        author_id   = nwsrow.author_id,
                        content     = contract_content,
                        ID          = nwsrow.ID,
                        part        = nwsrow.part,
                        post_date   = nwsrow.post_date.ToString(),
                        title       = nwsrow.title
                    };
                    showList.Add(temp);
                }

                var rr = new RestfulResult.RestfulArray <EncyclopediaForShow>();
                rr.code    = 1;
                rr.message = "成功查询到结果";
                rr.data    = showList.ToArray();
                return(new JsonResult(rr));
            }
            catch (Exception exc)
            {
                RestfulResult.RestfulData rr = new RestfulResult.RestfulData(0, exc.Message);
                return(new JsonResult(rr));
            }
        }
예제 #3
0
    public void Init()
    {
        List <MinGanCiKu> dataList = DataReader <MinGanCiKu> .DataList;
        List <string>     list     = new List <string>();

        for (int i = 0; i < dataList.get_Count(); i++)
        {
            list.Add(dataList.get_Item(i).content);
        }
        this.KeywordSearch2Filter = new KeywordSearch(list);
    }
예제 #4
0
        private List <NewsForShow> NewsSearch(string keyword, string author_id)
        {
            //如果keyword为空,不做要求
            if (keyword == null)
            {
                keyword = "";
            }
            //如果authorid为空,则不做要求
            bool isAuthorId = true;

            if (author_id == string.Empty || author_id == null)
            {
                isAuthorId = false;
            }
            var newsList = from news in _context.News
                           where (KeywordSearch.ContainsKeywords(news.title + " " + news.content, keyword)) &&
                           ((!isAuthorId) || (news.author_id == author_id))
                           orderby news.post_date descending
                           select news;

            if (newsList.Count() == 0)
            {
                throw (new Exception("没有找到满足条件的数据"));
            }
            List <NewsForShow> showList         = new List <NewsForShow>();
            string             contract_content = new string("");

            foreach (news nwsrow in newsList)
            {
                if (nwsrow.content.Count() > 50)
                {
                    contract_content = nwsrow.content.Substring(0, 50) + "...";
                }
                else
                {
                    contract_content = nwsrow.content;
                }
                NewsForShow temp = new NewsForShow()
                {
                    author_name = nwsrow.author_name,
                    author_id   = nwsrow.author_id,
                    content     = contract_content,
                    news_id     = nwsrow.news_id,
                    part        = nwsrow.part,
                    post_date   = nwsrow.post_date.ToString(),
                    title       = nwsrow.title
                };
                showList.Add(temp);
            }
            return(showList);
        }
예제 #5
0
        protected virtual int GetProgress(ConquestState state, Item item, string keyword)
        {
            if (item == null)
            {
                return(0);
            }

            if (state.User == null)
            {
                return(0);
            }

            if (Item.IsNotNull && !item.TypeEquals(Item, ItemChildren))
            {
                if (ItemChangeReset)
                {
                    return(-state.Progress);
                }

                return(0);
            }

            if (!String.IsNullOrEmpty(KeywordReq) && !KeywordSearch.Execute(keyword, KeywordReq, KeywordIgnoreCaps))
            {
                if (KeywordChangeReset)
                {
                    return(-state.Progress);
                }

                return(0);
            }

            if (item.Amount > 1 && CheckAmount)
            {
                return(item.Amount);
            }

            return(1);
        }
예제 #6
0
        protected void btnKeywordSearchGo_Click(object sender, EventArgs e)
        {
            KeywordSearch search = new KeywordSearch();
            search.Keyword = txtKeyword.Text.Trim();

            if (CurrentUserSession != null 
                && Config.Users.InterestedInFieldEnabled && !Config.Users.DisableGenderInformation)
            {
                search.InterestedIn = CurrentUserSession.InterestedIn;
            }

            UserSearchResults results = search.GetResults();
            SearchResults.ShowLastOnline = true;
            SearchResults.ShowViewedOn = false;
            SearchResults.ShowDistance = true;

            SearchResults.Results = results;

            pnlQuickSearch.Visible = false;
            pnlFilterOnline.Visible = false;
            pnlSearchResults.Visible = true;
        }
예제 #7
0
        public async Task <int> CreateKeywordSearchAsync(int workspaceArtifactId)
        {
            Console2.WriteDisplayStartLine("Creating Keyword search for DtSearch Index");

            try
            {
                SearchContainerRef searchFolder = new SearchContainerRef();

                KeywordSearch keywordSearch = new KeywordSearch
                {
                    Name            = Constants.Search.KeywordSearch.NAME,
                    SearchContainer = searchFolder
                };

                // Get all the query fields available to the current user.
                SearchResultViewFields searchResultViewFields = await KeywordSearchManager.GetFieldsForSearchResultViewAsync(workspaceArtifactId, Constants.DOCUMENT_ARTIFACT_TYPE);

                // Set the owner to the current user, in this case "Admin, Relativity," or "0" for public.
                List <UserRef> searchOwners = await KeywordSearchManager.GetSearchOwnersAsync(workspaceArtifactId);

                keywordSearch.Owner = searchOwners.First(o => o.Name == Constants.Search.KeywordSearch.OWNER);

                // Add the fields to the Fields collection.
                // If a field Name, ArtifactID, Guid, or ViewFieldID is known, a field can be set with that information as well.

                FieldRef fieldRef = searchResultViewFields.FieldsNotIncluded.First(f => f.Name == Constants.Search.KeywordSearch.FIELD_EDIT);
                keywordSearch.Fields.Add(fieldRef);

                fieldRef = searchResultViewFields.FieldsNotIncluded.First(f => f.Name == Constants.Search.KeywordSearch.FIELD_FILE_ICON);
                keywordSearch.Fields.Add(fieldRef);

                fieldRef = searchResultViewFields.FieldsNotIncluded.First(f => f.Name == Constants.Search.KeywordSearch.FIELD_CONTROL_NUMBER);
                keywordSearch.Fields.Add(fieldRef);

                // Create a Criteria for the field named "Extracted Text" where the value is set

                Criteria criteria = new Criteria
                {
                    Condition = new CriteriaCondition(
                        new FieldRef
                    {
                        Name = Constants.Search.KeywordSearch.CONDITION_FIELD_EXTRACTED_TEXT
                    }, CriteriaConditionEnum.IsSet)
                };

                // Add the search condition criteria to the collection.
                keywordSearch.SearchCriteria.Conditions.Add(criteria);

                // Add a note.

                keywordSearch.Notes          = Constants.Search.KeywordSearch.NOTES;
                keywordSearch.ArtifactTypeID = Constants.DOCUMENT_ARTIFACT_TYPE;

                // Create the search.
                int keywordSearchArtifactId = await KeywordSearchManager.CreateSingleAsync(workspaceArtifactId, keywordSearch);

                if (keywordSearchArtifactId == 0)
                {
                    throw new Exception("Failed to create the Keyword Search");
                }

                Console2.WriteDebugLine($"Keyword Search ArtifactId: {keywordSearchArtifactId}");
                Console2.WriteDisplayEndLine("Created Keyword search for DtSearch Index!");

                return(keywordSearchArtifactId);
            }
            catch (Exception ex)
            {
                throw new Exception("An error occured when creating Keyword Search", ex);
            }
        }
예제 #8
0
파일: Search.cs 프로젝트: cmcd74/SavvyCMS
        /// <summary>
        /// A simpler and faster version of the usual algorithm
        /// </summary>
        public static double CalculateScoreFast(string title, string fulltext, DateTime?itemDate, KeywordSearch keywords)
        {
            //' calculate score of this record
            //' give priority to whole search phrase, title matches, whole word matches, correct case matches
            double score = 0;

            if (keywords.Keyphrases.Count > 1)
            {
                // more than one phrase or word
                //' see if it contains the whole exact phrase
                score = score + ScoreMatches(title, keywords.OriginalKeywords) * 3;
                score = score + ScoreMatches(fulltext, keywords.OriginalKeywords) * 2;
            }

            //' see if it contains any of the keywords
            foreach (string keyword in keywords.Keyphrases)
            {
                score = score + ScoreMatches(title, keyword) * 2;
                score = score + ScoreMatches(fulltext, keyword);
            }            //next

            //' add bonus points if it is a recent article
            if (score > 0)            // then
            {
                DateTime now = DateTime.Now;
                if (!IsNull(itemDate))                // then
                {
                    double daysAgo = (now - itemDate.Value).TotalDays;
                    if (daysAgo < 15)
                    {
                        score = score + 22 - daysAgo;
                    }
                    else if (daysAgo < 30)
                    {
                        score = score + 5;
                    }
                    else if (daysAgo < 90)
                    {
                        score = score + 3;
                    }
                    else if (daysAgo < 365)
                    {
                        score = score + 0;
                    }
                    else if (daysAgo < 365 * 2)
                    {
                        score = score - 5;
                    }
                    else
                    {
                        double quartersAgo = daysAgo / 90;
                        score = score - quartersAgo;
                    }
                }        //end if
            }            //end if

            return(score);
        }
예제 #9
0
        public IActionResult Get([FromBody] dynamic _in)
        {
            try
            {
                //搜索条件
                string keyword    = _in.keyword;
                bool   isOnlyPost = _in.isOnlyPost;
                string user_id    = _in.user_id;
                //如果keyword为空,不做要求
                if (keyword == null)
                {
                    keyword = "";
                }
                //如果userid为空,不做要求
                bool isId = true;
                if (user_id == "" || user_id == null)
                {
                    isId = false;
                }
                //获得表单数据
                var postList = from post in _context.Post_data
                               join user in _context.user_data
                               on post.user_id equals user.user_id
                               where (KeywordSearch.ContainsKeywords(post.title + " " + post.content, keyword)) &&
                               ((!isId) || (post.user_id == user_id))
                               orderby post.post_date descending
                               select new { post, user };

                var replyList = from reply in _context.Reply_data
                                join user in _context.user_data
                                on reply.user_id equals user.user_id
                                where (!isOnlyPost) &
                                (KeywordSearch.ContainsKeywords(reply.content, keyword)) &&
                                ((!isId) || (reply.user_id == user_id))
                                orderby reply.reply_date descending
                                select new { reply, user };
                //没找到数据的异常
                if (postList.Count() + replyList.Count() == 0)
                {
                    throw (new Exception("没找到满足要求的贴"));
                }
                //将表单数据转化为展示数据
                var showList         = new List <PostOrReplyForShow>();
                var contract_content = new string("");
                foreach (var postRow in postList)
                {
                    if (postRow.post.content.Count() > 50)
                    {
                        contract_content = postRow.post.content.Substring(0, 50) + "...";
                    }
                    else
                    {
                        contract_content = postRow.post.content;
                    }
                    var temp = new PostOrReplyForShow
                    {
                        content   = contract_content,
                        date      = postRow.post.post_date.ToString(),
                        isPost    = true,
                        post_id   = postRow.post.post_id,
                        title     = postRow.post.title,
                        user_id   = postRow.post.user_id,
                        user_name = postRow.user.user_name
                    };
                    showList.Add(temp);
                }
                foreach (var replyRow in replyList)
                {
                    if (replyRow.reply.content.Count() > 50)
                    {
                        contract_content = replyRow.reply.content.Substring(0, 50) + "...";
                    }
                    else
                    {
                        contract_content = replyRow.reply.content;
                    }
                    var title = _context.Post_data.Find(replyRow.reply.post_id).title;
                    var temp  = new PostOrReplyForShow
                    {
                        content   = contract_content,
                        date      = replyRow.reply.reply_date.ToString(),
                        isPost    = true,
                        post_id   = replyRow.reply.post_id,
                        title     = title,
                        user_id   = replyRow.reply.user_id,
                        user_name = replyRow.user.user_name
                    };
                    showList.Add(temp);
                }
                //整理数据
                showList.Sort((x, y) =>
                {
                    if (Convert.ToDateTime(x.date) > Convert.ToDateTime(x.date))
                    {
                        return(-1);
                    }
                    else
                    {
                        return(1);
                    }
                });
                //返回正确结果
                RestfulResult.RestfulArray <PostOrReplyForShow> rr = new RestfulResult.RestfulArray <PostOrReplyForShow>();
                rr.code    = 1;
                rr.message = "成功搜索到目标贴";
                rr.data    = showList.ToArray();
                return(new JsonResult(rr));
            }
            catch (Exception exc)
            {
                RestfulResult.RestfulData rr = new RestfulResult.RestfulData(0, exc.Message);
                return(new JsonResult(rr));
            }
        }
예제 #10
0
        public ActionResult Search(string searchText)
        {
            var data = new ViewModel();

            data.ContentPage = Models.Page.LoadOrCreatePageCode("Search");
            if (data.ContentPage == null)
            {
                throw new Exception("Search page not found");
            }
            data.SearchText = searchText;
            data.SearchArea = String.IsNullOrEmpty(Web.Request["SearchArea"]) ? "All" : Web.Request["SearchArea"];
            int itemsPerPage;

            if (data.SearchArea == "All")
            {
                itemsPerPage = 5;
            }
            else
            {
                itemsPerPage = 25;
            }

            string keywords = searchText;
            var    search   = new KeywordSearch(keywords);

            //#if pages

            if (searchText.IsNotBlank())
            {
                /*	if (data.SearchArea == "All" || data.SearchArea == "Pages") {
                 *              Sql sql = new Sql("select * from Page");
                 *              sql.AddSql(search.FullTextJoin("page"));
                 *              sql.WhereIsActive<Page>();
                 *              //sql.Add("and (rolesallowed is null)");   // if using page user access control
                 *              sql.Add("order by Rank desc,Title");
                 *              sql.Paging(itemsPerPage);
                 *              data.PageResults = PageList.Load(sql);
                 *              data.Counter += sql.FetchCount();
                 *      }
                 *      if (data.SearchArea == "All" || data.SearchArea == "Faqs") {
                 *              Sql sql = new Sql("select * from FAQItem");
                 *              sql.AddSql(search.FullTextJoin("FAQItem"));
                 *              sql.WhereIsActive<FAQItem>();
                 *              sql.Add("order by Rank,FAQTitle");
                 *              sql.Paging(itemsPerPage);
                 *              data.FaqItems = FAQItemList.Load(sql);
                 *              data.Counter += sql.FetchCount();
                 *      }*/
                //if (data.SearchArea == "All" || data.SearchArea == "News") {
                //	Sql sql = new Sql("select * from News");
                //	sql.AddSql(search.FullTextJoin("News"));
                //	//sql.WhereIsActive<News>();
                //	sql.Add("order by Rank,Source");
                //	sql.Paging(itemsPerPage);
                //	//data.NewsItems = NewsList.Load(sql);
                //	data.Counter += sql.FetchCount();
                //}
                //if (data.SearchArea == "All" || data.SearchArea == "Products") {
                //	Sql sql = new Sql("select * from Product");
                //	sql.AddSql(search.FullTextJoin("Product"));
                //	//sql.WhereIsActive<Product>();
                //	sql.Add("order by Rank desc,Title");
                //	sql.Paging(itemsPerPage);
                //	//data.ProductItems = ProductList.Load(sql);
                //	data.Counter += sql.FetchCount();
                //}
            }

            data.NumPages = Html.CalcPageCount(data.Counter, itemsPerPage);
            // note: for full text search, instead use
            var keywordSearch = new Beweb.KeywordSearch(searchText);
            var columns       = keywordSearch.GetSqlFullTextWhereForTable("Page");

            if (columns.IsNotBlank())
            {
                var sql = new Sql("select * from Page where 1=1");
                sql.Add("and historypageid is null");                 // if page revisions
                sql.AddRawSqlString(columns);
                sql.AndIsActive <Page>();
                data.PageResults = PageList.Load(sql);
            }

            columns = keywordSearch.GetSqlFullTextWhereForTable("Event");
            if (columns.IsNotBlank())
            {
                var sql = new Sql("select * from event where 1=1");
                sql.AddRawSqlString(columns);
                sql.AndIsActive <Event>();
                data.EventResults = EventList.Load(sql);
            }

            columns = keywordSearch.GetSqlFullTextWhereForTable("News");
            if (columns.IsNotBlank())
            {
                var sql = new Sql("select * from News where 1=1");
                sql.AddRawSqlString(keywordSearch.GetSqlFullTextWhereForTable("News"));
                sql.AndIsActive <News>();
                data.NewsResults = NewsList.Load(sql);
            }
            //#endif
            return(View("SearchResults", data));
        }
예제 #11
0
        public void ProcessRequest(HttpContext context)
        {
            string m_Type   = context.Request["request"].ToLower();
            string m_Key    = context.Request["where"];
            int    m_Page   = Convert.ToInt32(context.Request["page"]);
            int    m_Size   = Convert.ToInt32(context.Request["maxfeatures"]);
            string callback = Convert.ToString(context.Request["callback"]);

            context.Response.ContentType = "text/plain";
            switch (m_Type)
            {
            case "query":
                switch (context.Request.QueryString["type"])
                {
                case "poi":
                    context.Response.Write(callback + "(" + KeywordSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "station":
                    context.Response.Write(callback + "(" + StationSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "line":
                    context.Response.Write(callback + "(" + LineSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;

                case "switch":
                    context.Response.Write(callback + "(" + SwitchSearch.GetFeature(m_Key, m_Size, m_Page) + ")");
                    break;
                }
                if (context.Request.QueryString["type"] == "poi")
                {
                }
                else if (context.Request.QueryString["type"] == "station")
                {
                }
                else if (context.Request.QueryString["type"] == "line")
                {
                }
                else if (context.Request.QueryString["type"] == "switch")
                {
                }
                break;

            case "buff":
                double m_X      = Convert.ToDouble(context.Request["x"]);
                double m_Y      = Convert.ToDouble(context.Request["y"]);
                double m_Radius = Convert.ToDouble(context.Request["r"]);

                context.Response.Write(callback + "(" + KeywordBuffer.GetFeature(m_Key, m_Size, m_Page, m_X, m_Y, m_Radius) + ")");
                break;

            case "spatialquery":
                if (context.Request.QueryString["bbox"] != null)
                {
                    string   bbox = context.Request["bbox"];
                    string[] ls   = bbox.Split(new char[] { ',' });
                    double   m_l  = Convert.ToDouble(ls[0]);
                    double   m_b  = Convert.ToDouble(ls[1]);
                    double   m_r  = Convert.ToDouble(ls[2]);
                    double   m_t  = Convert.ToDouble(ls[3]);
                    context.Response.Write(callback + "(" + KeywordRectangle.GetFeature(m_Key, m_Size, m_Page, m_l, m_b, m_r, m_t) + ")");
                }
                else if (context.Request.QueryString["point"] != null)
                {
                    string   paras = context.Request["point"];
                    string[] parms = paras.Split(new char[] { ',' });
                    double   m_x   = Convert.ToDouble(parms[0]);
                    double   m_y   = Convert.ToDouble(parms[1]);
                    double   m_r   = Convert.ToDouble(parms[2]);
                    context.Response.Write(callback + "(" + KeywordBuffer.GetFeature(m_Key, m_Size, m_Page, m_x, m_y, m_r) + ")");
                }
                break;
            }
        }