Ejemplo n.º 1
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="searchCriteria"></param>
        /// <param name="pageSize"></param>
        /// <param name="currentPage"></param>
        /// <returns></returns>
        public SearchModel Get(SearchCriteria searchCriteria, int pageSize = 10, int currentPage = 1)
        {
            getQueryFromCriteria(searchCriteria);
            this.WorkingSearchModel.ResultComponent = BexisIndexSearcher.search(bexisSearching, SearchConfig.headerItemXmlNodeList);

            return(this.WorkingSearchModel);
        }
Ejemplo n.º 2
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        public void updateIndex(Dictionary <long, IndexingAction> datasetsToIndex)
        {
            using (DatasetManager dm = new DatasetManager())
            {
                try
                {
                    if (!isIndexConfigured)
                    {
                        this.configureBexisIndexing(false);
                    }
                    foreach (KeyValuePair <long, IndexingAction> pair in datasetsToIndex)
                    {
                        if (pair.Value == IndexingAction.CREATE)
                        {
                            Query   query = new TermQuery(new Term("doc_id", pair.Key.ToString()));
                            TopDocs tds   = BexisIndexSearcher.getIndexSearcher().Search(query, 1);

                            if (tds.TotalHits < 1)
                            {
                                writeBexisIndex(pair.Key, dm.GetDatasetLatestMetadataVersion(pair.Key));
                            }
                            else
                            {
                                indexWriter.DeleteDocuments(new Term("doc_id", pair.Key.ToString()));
                                autoCompleteIndexWriter.DeleteDocuments(new Term("id", pair.Key.ToString()));
                                writeBexisIndex(pair.Key, dm.GetDatasetLatestMetadataVersion(pair.Key));
                            }
                        }
                        else if (pair.Value == IndexingAction.DELETE)
                        {
                            indexWriter.DeleteDocuments(new Term("doc_id", pair.Key.ToString()));
                            autoCompleteIndexWriter.DeleteDocuments(new Term("id", pair.Key.ToString()));
                        }
                        else if (pair.Value == IndexingAction.UPDATE)
                        {
                            indexWriter.DeleteDocuments(new Term("doc_id", pair.Key.ToString()));
                            autoCompleteIndexWriter.DeleteDocuments(new Term("id", pair.Key.ToString()));
                            writeBexisIndex(pair.Key, dm.GetDatasetLatestMetadataVersion(pair.Key));
                        }
                    }
                    indexWriter.Commit();
                    autoCompleteIndexWriter.Commit();
                    BexisIndexSearcher.searcher             = new IndexSearcher(indexWriter.GetReader());
                    BexisIndexSearcher._Reader              = indexWriter.GetReader();
                    BexisIndexSearcher.autoCompleteSearcher = new IndexSearcher(autoCompleteIndexWriter.GetReader());
                }
                catch (Exception ex)
                {
                    throw ex;
                }
                finally
                {
                    autoCompleteIndexWriter.Dispose();
                    indexWriter.Dispose();

                    BexisIndexSearcher.searcher             = new IndexSearcher(indexWriter.GetReader());
                    BexisIndexSearcher.autoCompleteSearcher = new IndexSearcher(autoCompleteIndexWriter.GetReader());
                }
            }
        }
Ejemplo n.º 3
0
        public void updateSingleDatasetIndex(long datasetId, IndexingAction indAction)
        {
            try
            {
                if (!isIndexConfigured)
                {
                    this.configureBexisIndexing(false);
                }
                DatasetManager dm = new DatasetManager();
                if (indAction == IndexingAction.CREATE)
                {
                    Query   query = new TermQuery(new Term("doc_id", datasetId.ToString()));
                    TopDocs tds   = BexisIndexSearcher.getIndexSearcher().Search(query, 1);

                    this.includePrimaryData = false;

                    if (tds.TotalHits < 1)
                    {
                        writeBexisIndex(datasetId, dm.GetDatasetLatestMetadataVersion(datasetId));
                    }
                    else
                    {
                        indexWriter.DeleteDocuments(new Term("doc_id", datasetId.ToString()));
                        autoCompleteIndexWriter.DeleteDocuments(new Term("id", datasetId.ToString()));
                        writeBexisIndex(datasetId, dm.GetDatasetLatestMetadataVersion(datasetId));
                    }
                }
                else if (indAction == IndexingAction.DELETE)
                {
                    indexWriter.DeleteDocuments(new Term("doc_id", datasetId.ToString()));
                    autoCompleteIndexWriter.DeleteDocuments(new Term("id", datasetId.ToString()));
                }
                else if (indAction == IndexingAction.UPDATE)
                {
                    indexWriter.DeleteDocuments(new Term("doc_id", datasetId.ToString()));
                    autoCompleteIndexWriter.DeleteDocuments(new Term("id", datasetId.ToString()));
                    writeBexisIndex(datasetId, dm.GetDatasetLatestMetadataVersion(datasetId));
                }

                indexWriter.Commit();
                autoCompleteIndexWriter.Commit();
                BexisIndexSearcher.searcher             = new IndexSearcher(indexWriter.GetReader());
                BexisIndexSearcher._Reader              = indexWriter.GetReader();
                BexisIndexSearcher.autoCompleteSearcher = new IndexSearcher(autoCompleteIndexWriter.GetReader());
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                BexisIndexSearcher.searcher             = new IndexSearcher(indexWriter.GetReader());
                BexisIndexSearcher.autoCompleteSearcher = new IndexSearcher(autoCompleteIndexWriter.GetReader());

                indexWriter.Dispose();
                autoCompleteIndexWriter.Dispose();
            }
        }
Ejemplo n.º 4
0
        public SearchModel UpdateProperties(SearchCriteria searchCriteria = null)
        {
            if (searchCriteria == null)
            {
                searchCriteria = new SearchCriteria();
            }
            getQueryFromCriteria(searchCriteria);

            this.WorkingSearchModel.SearchComponent.Properties = BexisIndexSearcher.propertySearch(this.bexisSearching, this.WorkingSearchModel.SearchComponent.Properties);

            return(this.WorkingSearchModel);
        }
Ejemplo n.º 5
0
        public SearchModel UpdateFacets(SearchCriteria searchCriteria = null)
        {
            if (searchCriteria == null)
            {
                searchCriteria = new SearchCriteria();
            }
            getQueryFromCriteria(searchCriteria);

            this.WorkingSearchModel.SearchComponent.Facets = BexisIndexSearcher.facetSearch(this.bexisSearching, this.WorkingSearchModel.SearchComponent.Facets);

            return(this.WorkingSearchModel);
        }
Ejemplo n.º 6
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        /// <param name="value"></param>
        /// <param name="filter"></param>
        /// <param name="searchType"></param>
        /// <param name="numberOfResults"></param>
        /// <returns></returns>
        public SearchModel GetTextBoxSearchValues(string value, string filter, string searchType, int numberOfResults)
        {
            if (searchType.Equals("basedon"))
            {
                getQueryFromCriteria(this.WorkingSearchModel.CriteriaComponent);
            }
            if (searchType.Equals("new"))
            {
                getQueryFromCriteria(new SearchCriteria());
            }

            // encoding special characters for lucene
            value = EncoderHelper.Encode(value);

            this.WorkingSearchModel.SearchComponent.TextBoxSearchValues = BexisIndexSearcher.doTextSearch(this.bexisSearching, filter, value);
            return(this.WorkingSearchModel);
        }
Ejemplo n.º 7
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        public static void Reset()
        {
            isLoaded  = false;
            configXML = null;
            _Reader   = BexisIndexSearcher.getIndexReader();

            sIO = new searchInitObjects();

            AllFacetsDefault     = sIO.AllFacets;
            AllPropertiesDefault = sIO.AllProperties;
            AllCategoriesDefault = sIO.AllCategories;

            numericProperties = new HashSet <string>();

            facetXmlNodeList      = new List <XmlNode>();
            propertyXmlNodeList   = new List <XmlNode>();
            categoryXmlNodeList   = new List <XmlNode>();
            generalXmlNodeList    = new List <XmlNode>();
            headerItemXmlNodeList = new List <XmlNode>();
        }
Ejemplo n.º 8
0
 /// <summary>
 ///
 /// </summary>
 /// <remarks></remarks>
 /// <seealso cref=""/>
 /// <param name="searchCriteria"></param>
 /// <return></return>
 private void getQueryFromCriteria(SearchCriteria searchCriteria)
 {
     if (searchCriteria.SearchCriteriaList.Count() > 0)
     {
         bexisSearching = new BooleanQuery();
         foreach (SearchCriterion sco in searchCriteria.SearchCriteriaList)
         {
             if (sco.Values.Count > 0)
             {
                 if (sco.SearchComponent.Type.Equals(SearchComponentBaseType.General))
                 {
                     String       fieldName             = sco.SearchComponent.Name;
                     BooleanQuery bexisSearchingGeneral = new BooleanQuery();
                     foreach (String value in sco.Values)
                     {
                         String encodedValue = value;
                         Query  query        = new TermQuery(new Term(fieldName, encodedValue));
                         bexisSearchingGeneral.Add(query, Occur.SHOULD);
                     }
                     ((BooleanQuery)bexisSearching).Add(bexisSearchingGeneral, Occur.MUST);
                 }
                 else if (sco.SearchComponent.Type.Equals(SearchComponentBaseType.Category))
                 {
                     BooleanQuery bexisSearchingCategory = new BooleanQuery();
                     String       fieldName = "category_" + sco.SearchComponent.Name;
                     QueryParser  parser;
                     if (fieldName.ToLower().Equals("category_all"))
                     {
                         List <string> temp2 = BexisIndexSearcher.getCategoryFields().ToList();
                         temp2.AddRange(BexisIndexSearcher.getStoredFields().ToList());
                         temp2.Add("ng_all");
                         parser = new MultiFieldQueryParser(Lucene.Net.Util.Version.LUCENE_30, temp2.ToArray(), new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
                     }
                     else
                     {
                         parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, fieldName, new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30));
                     }
                     foreach (String value in sco.Values)
                     {
                         String encodedValue = EncoderHelper.Encode(value);
                         String newString    = null;
                         //string value = val.Replace(")", "").Replace("(", "");
                         char[]   delimiter = new char[] { ';', ' ', ',', '!', '.' };
                         string[] parts     = encodedValue.ToLower().Split(delimiter, StringSplitOptions.RemoveEmptyEntries);
                         for (int i = 0; i < parts.Length; i++)
                         {
                             newString = newString + " " + parts[i] + "~0.6";
                         }
                         parser.PhraseSlop      = 5;
                         parser.DefaultOperator = QueryParser.AND_OPERATOR;
                         string query_value = encodedValue;
                         if (encodedValue.Equals(""))
                         {
                             query_value = "*:*";
                         }
                         Query query = parser.Parse(query_value);
                         bexisSearchingCategory.Add(query, Occur.SHOULD);
                     }
                     ((BooleanQuery)bexisSearching).Add(bexisSearchingCategory, Occur.MUST);
                 }
                 else if (sco.SearchComponent.Type.Equals(SearchComponentBaseType.Facet))
                 {
                     String       fieldName           = "facet_" + sco.SearchComponent.Name;
                     BooleanQuery bexisSearchingFacet = new BooleanQuery();
                     foreach (String value in sco.Values)
                     {
                         String encodedValue = value;
                         Query  query        = new TermQuery(new Term(fieldName, encodedValue));
                         bexisSearchingFacet.Add(query, Occur.SHOULD);
                     }
                     ((BooleanQuery)bexisSearching).Add(bexisSearchingFacet, Occur.MUST);
                 }
                 else if (sco.SearchComponent.Type.Equals(SearchComponentBaseType.Property))
                 {
                     String   fieldName = "property_" + sco.SearchComponent.Name;
                     Property pp        = (Property)sco.SearchComponent;
                     if (pp.UIComponent.ToLower().Equals("range"))
                     {
                         fieldName = "property_numeric_" + sco.SearchComponent.Name;
                         DateTime dd = new DateTime(Int32.Parse(sco.Values[0]), 1, 1, 1, 1, 1);
                         if (pp.Direction == Direction.increase)
                         {
                             NumericRangeQuery <long> dateRangeQuery = NumericRangeQuery.NewLongRange(fieldName, dd.Ticks, long.MaxValue, true, true);
                             ((BooleanQuery)bexisSearching).Add(dateRangeQuery, Occur.MUST);
                         }
                         else
                         {
                             NumericRangeQuery <long> dateRangeQuery = NumericRangeQuery.NewLongRange(fieldName, long.MinValue, dd.Ticks, true, true);
                             ((BooleanQuery)bexisSearching).Add(dateRangeQuery, Occur.MUST);
                         }
                     }
                     else
                     {
                         BooleanQuery bexisSearchingProperty = new BooleanQuery();
                         foreach (String value in sco.Values)
                         {
                             if (value.ToLower().Equals("all"))
                             {
                                 Query query = new MatchAllDocsQuery();
                                 bexisSearchingProperty.Add(query, Occur.SHOULD);
                             }
                             else
                             {
                                 String encodedValue = value;
                                 if (SearchConfig.getNumericProperties().Contains(sco.SearchComponent.Name.ToLower()))
                                 {
                                 }
                                 else
                                 {
                                     Query query = new TermQuery(new Term(fieldName, encodedValue));
                                     bexisSearchingProperty.Add(query, Occur.SHOULD);
                                 }
                             }
                         }
                         ((BooleanQuery)bexisSearching).Add(bexisSearchingProperty, Occur.MUST);
                     }
                 }
             }
             else
             {
                 //do nothing yet
             }
         }
     }
     else
     {
         using (var sa = new SimpleAnalyzer())
         {
             QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "id", sa);
             bexisSearching = parser.Parse("*:*");
         }
     }
 }
Ejemplo n.º 9
0
        /// <summary>
        ///
        /// </summary>
        /// <remarks></remarks>
        /// <seealso cref=""/>
        private static void Load()
        {
            configXML = new XmlDocument();

            configXML.Load(FileHelper.ConfigFilePath);
            XmlNodeList fieldProperties = configXML.GetElementsByTagName("field");

            Category categoryDefault = new Category();

            categoryDefault.Name         = "All";
            categoryDefault.Value        = "All";
            categoryDefault.DisplayName  = "All";
            categoryDefault.DefaultValue = "nothing";
            AllCategoriesDefault.Add(categoryDefault);
            foreach (XmlNode fieldProperty in fieldProperties)
            {
                if (!fieldProperty.Attributes.GetNamedItem("type").Value.ToLower().Equals("primary_data_field"))
                {
                    String headerItem = fieldProperty.Attributes.GetNamedItem("header_item").Value;
                    String storeItem  = fieldProperty.Attributes.GetNamedItem("store").Value;
                    if (headerItem.ToLower().Equals("yes") && storeItem.ToLower().Equals("yes"))
                    {
                        headerItemXmlNodeList.Add(fieldProperty);
                    }

                    String fieldType = fieldProperty.Attributes.GetNamedItem("type").Value;
                    String fieldName = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;

                    String primitiveType = fieldProperty.Attributes.GetNamedItem("primitive_type").Value;
                    if (!primitiveType.ToLower().Equals("string"))
                    {
                        numericProperties.Add(fieldName.ToLower());
                    }

                    if (fieldType.ToLower().Equals("facet_field"))
                    {
                        facetXmlNodeList.Add(fieldProperty);
                        Facet cDefault = new Facet();
                        cDefault.Name        = fieldName;
                        cDefault.Text        = fieldName;
                        cDefault.Value       = fieldName;
                        cDefault.DisplayName = fieldProperty.Attributes.GetNamedItem("display_name").Value;

                        cDefault.Childrens = new List <Facet>();
                        List <Facet> lcDefault = new List <Facet>();
                        try
                        {
                            _Reader = BexisIndexSearcher.getIndexReader();
                            Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "id", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_30)).Parse("*:*");
                            using (SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "facet_" + fieldName }))
                            {
                                SimpleFacetedSearch.Hits hits = sfs.Search(query);

                                int cCount = 0;
                                foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
                                {
                                    if (!hpg.Name.ToString().Equals(""))
                                    {
                                        Facet ccDefault = new Facet();
                                        ccDefault.Name  = hpg.Name.ToString();
                                        ccDefault.Text  = hpg.Name.ToString();
                                        ccDefault.Value = hpg.Name.ToString();
                                        ccDefault.Count = (int)hpg.HitCount;
                                        if (ccDefault.Count > 0)
                                        {
                                            cCount++;
                                        }
                                        cDefault.Childrens.Add(ccDefault);
                                    }
                                }
                                cDefault.Count = cCount;
                                AllFacetsDefault.Add(cDefault);
                            }
                        }
                        catch
                        {
                        }
                    }

                    else if (fieldType.ToLower().Equals("property_field"))
                    {
                        propertyXmlNodeList.Add(fieldProperty);
                        Property cDefault = new Property();
                        //c.Id = x.Attributes[Property.ID].InnerText;
                        cDefault.Name            = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;
                        cDefault.DisplayName     = fieldProperty.Attributes.GetNamedItem("display_name").Value;
                        cDefault.DisplayTitle    = fieldProperty.Attributes.GetNamedItem("display_name").Value;
                        cDefault.DataSourceKey   = fieldProperty.Attributes.GetNamedItem("metadata_name").Value;
                        cDefault.UIComponent     = fieldProperty.Attributes.GetNamedItem("uiComponent").Value;;
                        cDefault.AggregationType = fieldProperty.Attributes.GetNamedItem("aggregationType").Value;
                        cDefault.DefaultValue    = "All";
                        cDefault.DataType        = fieldProperty.Attributes.GetNamedItem("primitive_type").Value;
                        if (cDefault.UIComponent.ToLower().Equals("range") && cDefault.DataType.ToLower().Equals("date"))
                        {
                            String direction = fieldProperty.Attributes.GetNamedItem("direction").Value;

                            if (direction.ToLower().Equals("increase"))
                            {
                                cDefault.Direction = Direction.increase;
                            }
                            else
                            {
                                cDefault.Direction = Direction.decrease;
                            }
                        }


                        Query query = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "id", new StandardAnalyzer(Lucene.Net.Util.Version.LUCENE_29)).Parse("*:*");
                        try
                        {
                            _Reader = BexisIndexSearcher.getIndexReader();


                            using (SimpleFacetedSearch sfs = new SimpleFacetedSearch(_Reader, new string[] { "property_" + fieldName }))
                            {
                                SimpleFacetedSearch.Hits hits      = sfs.Search(query);
                                List <string>            laDefault = new List <string>();
                                foreach (SimpleFacetedSearch.HitsPerFacet hpg in hits.HitsPerFacet)
                                {
                                    if (!string.IsNullOrEmpty(hpg?.Name?.ToString()))
                                    {
                                        laDefault.Add(hpg.Name.ToString());
                                    }
                                }

                                //if (!cDefault.UIComponent.ToLower().Equals("range")) { laDefault.Add("All"); };
                                laDefault.Sort();
                                cDefault.Values = laDefault;
                                AllPropertiesDefault.Add(cDefault);
                            }
                        }
                        catch
                        {
                            throw;
                        }
                    }
                    else if (fieldType.ToLower().Equals("category_field"))
                    {
                        categoryXmlNodeList.Add(fieldProperty);

                        Category cDefault = new Category();
                        cDefault.Name         = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;
                        cDefault.DisplayName  = fieldProperty.Attributes.GetNamedItem("display_name").Value;
                        cDefault.Value        = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;;
                        cDefault.DefaultValue = "nothing";

                        AllCategoriesDefault.Add(cDefault);
                    }
                    else if (fieldType.ToLower().Equals("general_field"))
                    {
                        generalXmlNodeList.Add(fieldProperty);
                    }
                }
                else if (fieldProperty.Attributes.GetNamedItem("type").Value.ToLower().Equals("primary_data_field"))
                {
                    categoryXmlNodeList.Add(fieldProperty);
                    Category cDefault = new Category();
                    cDefault.Name         = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;
                    cDefault.DisplayName  = fieldProperty.Attributes.GetNamedItem("display_name").Value;
                    cDefault.Value        = fieldProperty.Attributes.GetNamedItem("lucene_name").Value;;
                    cDefault.DefaultValue = "nothing";
                    AllCategoriesDefault.Add(cDefault);
                }
            }
        }