예제 #1
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="query"></param>
        /// <param name="headerItemXmlNodeList"></param>
        /// <returns></returns>
        public static SearchResult search(Query query, List <XmlNode> headerItemXmlNodeList)
        {
            TopDocs      docs = searcher.Search(query, 1000);
            SearchResult sro  = new SearchResult();

            sro.PageSize     = 10;
            sro.CurrentPage  = 1;
            sro.NumberOfHits = 100;

            List <HeaderItem> Header        = new List <HeaderItem>();
            List <HeaderItem> DefaultHeader = new List <HeaderItem>();

            // create id
            HeaderItem id = new HeaderItem();

            id.DisplayName = "ID";
            id.Name        = "ID";
            id.DataType    = "Integer";
            sro.Id         = id;
            Header.Add(id);
            DefaultHeader.Add(id);

            foreach (XmlNode ade in headerItemXmlNodeList)
            {
                HeaderItem hi = new HeaderItem();
                hi             = new HeaderItem();
                hi.Name        = ade.Attributes.GetNamedItem("lucene_name").Value;
                hi.DisplayName = ade.Attributes.GetNamedItem("display_name").Value;
                Header.Add(hi);

                if (ade.Attributes.GetNamedItem("default_visible_item").Value.ToLower().Equals("yes"))
                {
                    DefaultHeader.Add(hi);
                }
            }

            List <Row> RowList = new List <Row>();

            foreach (ScoreDoc sd in docs.ScoreDocs)
            {
                Document      doc       = searcher.Doc(sd.Doc);
                Row           r         = new Row();
                List <object> ValueList = new List <object>();
                ValueList = new List <object>();
                ValueList.Add(doc.Get("doc_id"));

                foreach (XmlNode ade in headerItemXmlNodeList)
                {
                    String fieldType  = ade.Attributes.GetNamedItem("type").Value;
                    String luceneName = ade.Attributes.GetNamedItem("lucene_name").Value;
                    if (fieldType.ToLower().Equals("facet_field"))
                    {
                        luceneName = "facet_" + luceneName;
                    }
                    else if (fieldType.ToLower().Equals("category_field"))
                    {
                        luceneName = "category_" + luceneName;
                    }
                    else if (fieldType.ToLower().Equals("property_field"))
                    {
                        luceneName = "property_" + luceneName;
                    }

                    ValueList.Add(doc.Get(luceneName));
                }
                r.Values = ValueList;
                RowList.Add(r);
            }

            sro.Header = Header;
            sro.DefaultVisibleHeaderItem = DefaultHeader;
            sro.Rows = RowList;
            return(sro);
        }
예제 #2
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="query"></param>
        /// <param name="headerItemXmlNodeList"></param>
        /// <returns></returns>
        public static SearchResult search(Query query, List<XmlNode> headerItemXmlNodeList)
        {
            int n = 0;
            DatasetManager dm = null;
            try
            {
                dm = new DatasetManager();
                n = dm.DatasetRepo.Get().Count;

                if (n == 0) n = 1000;
            }
            catch
            {
                n = 1000;
            }
            finally
            {
                dm.Dispose();
                if (n <= 0)
                    n = 1000;
            }
            TopDocs docs = searcher.Search(query, n);
            SearchResult sro = new SearchResult();
            sro.PageSize = 10;
            sro.CurrentPage = 1;
            sro.NumberOfHits = 100;

            List<HeaderItem> Header = new List<HeaderItem>();
            List<HeaderItem> DefaultHeader = new List<HeaderItem>();

            // create id
            HeaderItem id = new HeaderItem();
            id.DisplayName = "ID";
            id.Name = "ID";
            id.DataType = "Integer";
            sro.Id = id;
            Header.Add(id);
            DefaultHeader.Add(id);

            // create entity
            HeaderItem entity = new HeaderItem();
            entity.DisplayName = "Type";
            entity.Name = "entity_name";
            entity.DataType = "string";
            Header.Add(entity);

            //DefaultHeader.Add(entity);

            foreach (XmlNode ade in headerItemXmlNodeList)
            {
                HeaderItem hi = new HeaderItem();
                hi = new HeaderItem();
                hi.Name = ade.Attributes.GetNamedItem("lucene_name").Value;
                hi.DisplayName = ade.Attributes.GetNamedItem("display_name").Value;
                Header.Add(hi);

                if (ade.Attributes.GetNamedItem("default_visible_item").Value.ToLower().Equals("yes"))
                {
                    DefaultHeader.Add(hi);
                }
            }

            List<Row> RowList = new List<Row>();
            string valueLastEntity = ""; // var to store last entity value
            bool moreThanOneEntityFound = false; // var to set, if more than one entity name was found


            foreach (ScoreDoc sd in docs.ScoreDocs)
            {
                Document doc = searcher.Doc(sd.Doc);
                Row r = new Row();
                List<object> ValueList = new List<object>();
                ValueList = new List<object>();
                ValueList.Add(doc.Get("doc_id"));
                ValueList.Add(doc.Get("gen_entity_name"));

                // check if there are more than one entities in the result list
                if (moreThanOneEntityFound == false && ValueList[1].ToString() != valueLastEntity && valueLastEntity != "")
                {
                    moreThanOneEntityFound = true;
                }
                valueLastEntity = ValueList[1].ToString();  

                foreach (XmlNode ade in headerItemXmlNodeList)
                {
                    String fieldType = ade.Attributes.GetNamedItem("type").Value;
                    String luceneName = ade.Attributes.GetNamedItem("lucene_name").Value;
                    if (fieldType.ToLower().Equals("facet_field"))
                    {
                        luceneName = "facet_" + luceneName;
                    }
                    else if (fieldType.ToLower().Equals("category_field"))
                    {
                        luceneName = "category_" + luceneName;
                    }
                    else if (fieldType.ToLower().Equals("property_field"))
                    {
                        luceneName = "property_" + luceneName;
                    }

                    ValueList.Add(doc.Get(luceneName));
                }
                r.Values = ValueList;
                RowList.Add(r);
            }
          
            // show column of entities, if there are more than one found
            if (moreThanOneEntityFound == true)
            {
                DefaultHeader.Add(entity);
            }

            sro.Header = Header;
            sro.DefaultVisibleHeaderItem = DefaultHeader;
            sro.Rows = RowList;
            return sro;
        }