public void PDFIndexer_Ensure_ParentID_Honored() { //change parent id to 1116 var existingCriteria = ((IndexCriteria)_indexer.IndexerData); _indexer.IndexerData = new IndexCriteria(existingCriteria.StandardFields, existingCriteria.UserFields, existingCriteria.IncludeNodeTypes, existingCriteria.ExcludeNodeTypes, 1116); //get the 2112 pdf node: 2112 var node = _mediaService.GetLatestMediaByXpath("//*[string-length(@id)>0 and number(@id)>0]") .Root .Elements() .Where(x => (int)x.Attribute("id") == 2112) .First(); //create a copy of 2112 undneath 1111 which is 'not indexable' var newpdf = XElement.Parse(node.ToString()); newpdf.SetAttributeValue("id", "999999"); newpdf.SetAttributeValue("path", "-1,1111,999999"); newpdf.SetAttributeValue("parentID", "1111"); //now reindex _indexer.ReIndexNode(newpdf, IndexTypes.Media); //make sure it doesn't exist var results = _searcher.Search(_searcher.CreateSearchCriteria().Id(999999).Compile()); Assert.AreEqual(0, results.Count()); }
/// <summary> /// Executes the search. If the <paramref name="rootId"/> value is set the search will be executed for the site containing /// that content node only. /// </summary> /// <param name="rootId">The root id of the site to search within.</param> /// <returns>The <see cref="SearchResponse"/> containing the search results.</returns> public SearchResponse Execute(string rootId = "") { SearchResponse searchResponse = new SearchResponse(); UmbracoExamineSearcher searchProvider = (UmbracoExamineSearcher)ExamineManager.Instance.SearchProviderCollection[ZoombracoConstants.Search.SearcherName]; Analyzer analyzer = searchProvider.IndexingAnalyzer; // Wildcards are only supported using the languages using the standard analyzer. this.UseWildcards = this.UseWildcards && typeof(StandardAnalyzer) == analyzer.GetType(); IBooleanOperation searchCriteria = searchProvider.CreateSearchCriteria().OrderBy(string.Empty); if (!string.IsNullOrWhiteSpace(this.Query)) { string[] mergedFields = new string[this.Cultures.Length]; for (int i = 0; i < this.Cultures.Length; i++) { mergedFields[i] = string.Format(ZoombracoConstants.Search.MergedDataFieldTemplate, this.Cultures[i].Name); } if (this.UseWildcards) { searchCriteria = searchProvider .CreateSearchCriteria() .GroupedOr( mergedFields, this.Query.Split(new[] { " " }, StringSplitOptions.RemoveEmptyEntries).Select(w => w.Trim().MultipleCharacterWildcard()) .ToArray()); } else { searchCriteria = searchProvider .CreateSearchCriteria() .GroupedAnd(mergedFields, this.Query); } } if (this.Categories != null && this.Categories.Any()) { searchCriteria.And().Field(ZoombracoConstants.Search.CategoryField, string.Join(" ", this.Categories)); } if (!string.IsNullOrWhiteSpace(rootId)) { searchCriteria.And().Field(ZoombracoConstants.Search.SiteField, rootId); } if (searchCriteria != null) { ISearchResults searchResults = null; try { searchResults = searchProvider.Search(searchCriteria.Compile()); } catch (NullReferenceException) { // If the query object can't be compiled then an exception within Examine is raised } if (searchResults != null) { Formatter formatter = new SimpleHTMLFormatter("<strong>", "</strong>"); foreach (SearchResult searchResult in searchResults.Skip(this.Skip).Take(this.Take)) { foreach (CultureInfo culture in this.Cultures) { string fieldName = string.Format(ZoombracoConstants.Search.MergedDataFieldTemplate, culture.Name); string fieldResult = searchResult.Fields[fieldName]; this.AddSearchMatch(analyzer, formatter, searchResults, searchResponse, searchResult, fieldName, fieldResult); } } searchResponse.TotalCount = searchResults.TotalItemCount; } } return(searchResponse); }