/// <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) { MetadataReader.ListOfMetadata = MetadataReader.GetAllMetadataDatasets(); MetadataReader.ListOfMetadata = MetadataReader.GetAllMetadataDatasetsWithListOfSearchCriteria(MetadataReader.ListOfMetadata, searchCriteria); this.WorkingSearchModel.ResultComponent = ResultObjectBuilder.ConvertListOfMetadataToSearchResultObject(MetadataReader.ListOfMetadata, pageSize, currentPage); return this.WorkingSearchModel; }
// filter list by Value //public static List<Metadata> GetAllMetadataDatasetsWithListOfSearchValues(List<Metadata> data, Dictionary<string,List<string>> searchValues) //{ // IEnumerable<Metadata> newData = new List<Metadata>(); // List<Metadata> temp = new List<Metadata>(); // if (searchValues.Count() > 0) // { // bool first = true; // foreach (KeyValuePair<string,List<string>> kvp in searchValues) // { // IEnumerable<Metadata> tempValue = new List<Metadata>(); // temp = new List<Metadata>(); // if (kvp.Value.Count > 0) // { // IEnumerable<Metadata> newValueData = new List<Metadata>(); // foreach (string value in kvp.Value) // { // if (kvp.Key == "") temp = GetAllMetadataDatasetsByValue(data, value); // else temp = GetAllMetadataDatasetsByNode(data, kvp.Key, value); // if (tempValue.Count() == 0) tempValue = temp; // else // { // tempValue = tempValue.Union(temp); // } // } // if (first == false) // { // newData = newData.Intersect(tempValue); // } // else // { // newData = tempValue; // first = false; // } // } // else // { // if (first == true) // { // newData = data; // first = false; // } // else newData = newData.Intersect(data); // } // } // return newData.ToList(); // } // else return data; //} // filter list by Value public static List<Metadata> GetAllMetadataDatasetsWithListOfSearchCriteria(List<Metadata> data, SearchCriteria searchCriteria) { IEnumerable<Metadata> newData = new List<Metadata>(); List<Metadata> temp = new List<Metadata>(); if (searchCriteria.SearchCriteriaList.Count() > 0) { bool first = true; foreach (SearchCriterion sco in searchCriteria.SearchCriteriaList) { IEnumerable<Metadata> tempValue = new List<Metadata>(); temp = new List<Metadata>(); if (sco.Values.Count > 0) { IEnumerable<Metadata> newValueData = new List<Metadata>(); foreach (string value in sco.Values) { //newValueData = new List<Metadata>(); if (sco.SearchComponent.Name == "all") temp = GetAllMetadataDatasetsByValue(data, value); else { if (sco.SearchComponent.Type == SearchComponentBaseType.Property) { Property sc = (Property)sco.SearchComponent; if (sc.UIComponent == Property.UI_RANGE && sc.DataType == DataHelperConstClass.PROPERTY_DATATYPE_DATE) { bool desc = false; if (sc.DataSourceKey == "endDate") desc = true; temp = GetAllMetadataDatasetsByRangeNode(data, sco.SearchComponent.Name, value, desc); } else { temp = GetAllMetadataDatasetsByNode(data, sco.SearchComponent.Name, value); } } else { temp = GetAllMetadataDatasetsByNode(data, sco.SearchComponent.Name, value); } } if (tempValue.Count() == 0) tempValue = temp; else { tempValue = tempValue.Union(temp); } } if (first == false) { newData = newData.Intersect(tempValue); } else { newData = tempValue; first = false; } } else { if (first == true) { newData = data; first = false; } else newData = newData.Intersect(data); } } return newData.ToList(); } else return data; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="searchCriteria"></param> /// <returns></returns> public SearchModel UpdateFacets(SearchCriteria searchCriteria) { MetadataReader.ListOfMetadata = MetadataReader.GetAllMetadataDatasetsWithListOfSearchCriteria(MetadataReader.ListOfMetadata, searchCriteria); //facets this.WorkingSearchModel.SearchComponent.Facets = FacetBuilder.GetAllNodesAsListFromData(FacetBuilder.CATEGORY_TYPE, MetadataReader.ListOfMetadata); return this.WorkingSearchModel; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="searchCriteria"></param> /// <param name="pageSize"></param> /// <param name="currentPage"></param> /// <returns></returns> public SearchModel SearchAndUpdate(SearchCriteria searchCriteria, int pageSize = 10, int currentPage = 1) { this.WorkingSearchModel = Get(searchCriteria, pageSize, currentPage); this.WorkingSearchModel = UpdateFacets(searchCriteria); return this.WorkingSearchModel; }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="searchCriteria"></param> /// <return></return> public void SearchAndUpdate(SearchCriteria searchCriteria) { this.WorkingSearchModel = Get(searchCriteria); this.WorkingSearchModel = UpdateFacets(searchCriteria); }
/// <summary> /// /// </summary> /// <remarks></remarks> /// <seealso cref=""/> /// <param name="value"></param> /// <param name="filter"></param> /// <param name="searchType"></param> /// <param name="numberOfResults"></param> /// <param name="searchCriteria"></param> /// <returns></returns> public SearchModel GetTextBoxSearchValues(string value, string filter, string searchType, int numberOfResults, SearchCriteria searchCriteria) { throw new NotImplementedException(); }
/// <summary> /// Remove a property from the Dictionary /// </summary> /// <example> /// grassland: all | yes | no /// grassland is name /// value is (all | yes | no) /// </example> /// <param name="name">Name of the property</param> /// <param name="value">Value of the property</param> public void RemoveFromPropertiesDic(string name, string value, SearchCriteria sc) { if (name != null) { if (sc.GetProperty(name) != null) { string datasourceKey = sc.GetProperty(name).DataSourceKey; if (PropertiesDic.ContainsKey(datasourceKey)) { foreach (KeyValuePair<string, string> kvp in PropertiesDic) { if (kvp.Value == value && kvp.Key == datasourceKey) { PropertiesDic.Remove(datasourceKey); break; } } } } } }
/// <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; }
/// <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.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 { QueryParser parser = new QueryParser(Lucene.Net.Util.Version.LUCENE_30, "id", new SimpleAnalyzer()); bexisSearching = parser.Parse("*:*"); } }
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; }