コード例 #1
0
        /// <summary>
        /// Method for create and indexed Informaction in Lucenen files
        /// </summary>
        /// <param name="directoryInfo"></param>
        /// <param name="listDataIndexed"></param>
        private void IndexedData(DirectoryInfo directoryInfo, List <IndexDataDto> listDataIndexed)
        {
            using (Directory directory = FSDirectory.Open(directoryInfo))
                using (Analyzer analyzer = new StandardAnalyzer(Version.LUCENE_30))
                    using (var writer = new IndexWriter(directory, analyzer, new IndexWriter.MaxFieldLength(10000)))
                    {
                        //This list is for update State in the table AnalysisData whene object is indexed lucene file
                        List <Guid> listRequestUpdateState = new List <Guid>();

                        foreach (var item in listDataIndexed)
                        {
                            var    document   = new Document();
                            string objectIdEx = item.objectId.ToString();
                            //This try validate that is there is some error in registration can continue the System
                            try
                            {
                                string fullRequest = string.Empty;
                                fullRequest = string.Format("{0} {1} {2} {3} {4} {5} {6} {7} {8} {9} {10} {11} {12}", item.fullRequest, item.title, item.keywords, item.sentences, item.concepts, item.language, item.category, item.key, item.label, item.country, item.region, item.city, item.organizationName);
                                fullRequest = NexsoHelper.DecodeHtmlAndRemoveAccents(fullRequest.ToLower());

                                if (!item.objectId.Equals(Guid.Empty))
                                {
                                    document.Add(new Field("ObjetcId", item.objectId.ToString(), Field.Store.YES, Field.Index.NOT_ANALYZED));
                                }

                                if (!string.IsNullOrEmpty(item.fullRequest))
                                {
                                    document.Add(new Field("Title", NexsoHelper.DecodeHtmlAndRemoveAccents(item.title), Field.Store.YES, Field.Index.ANALYZED));
                                }

                                if (!string.IsNullOrEmpty(item.fullRequest))
                                {
                                    document.Add(new Field("OrganizationName", NexsoHelper.DecodeHtmlAndRemoveAccents(item.organizationName), Field.Store.YES, Field.Index.ANALYZED));
                                }


                                if (!string.IsNullOrEmpty(item.fullRequest))
                                {
                                    document.Add(new Field("FullRequest", fullRequest, Field.Store.YES, Field.Index.ANALYZED));
                                }
                                document.Boost = item.scoreValue;
                                writer.AddDocument(document);
                                listRequestUpdateState.Add(item.objectId);
                            }
                            catch (Exception ex)
                            {
                                DotNetNuke.Services.Exceptions.Exceptions.LogException(ex);
                            }
                        }
                        writer.Optimize();
                        writer.Flush(true, true, true);

                        if (listRequestUpdateState.Count > 0)
                        {
                            UpdateStateIndex(listRequestUpdateState);
                        }
                    }
        }
コード例 #2
0
        /// <summary>
        /// </summary>
        /// <param name="textSearcher">This is a text for get data</param>
        /// <returns>List of all Id gets for the search in Lucene Indexed files</returns>
        public List <string> SearcherId(string textSearcher)
        {
            var lReturn = new List <string>();

            DirectoryInfo directoryInfo = null;
            string        directoryPath = NexsoHelper.AssemblyDirectory.Replace("bin", "App_Data");

            directoryInfo = new DirectoryInfo(directoryPath + SettingsAppIndex.Default.LuceneFullPath);
            //This line is for remove Accents of text
            textSearcher = NexsoHelper.DecodeHtmlAndRemoveAccents(textSearcher.ToLower());

            if (directoryInfo != null)
            {
                GetDataIndexId(directoryInfo, ref textSearcher, ref lReturn);
            }

            return(lReturn);
        }