public void Re_Execute_Compiled_Expect_Same_Results() { TestHelper.IndexThings(new Thing[] { new Thing() { Name = "thing" } }); var lookQuery = new LookQuery(TestHelper.GetSearchingContext()) { NameQuery = new NameQuery() { Is = "thing" } }; Assert.IsNull(lookQuery.Compiled); var lookResults = lookQuery.Search(); var total = lookResults.TotalItemCount; Assert.IsNotNull(lookQuery.Compiled); Assert.IsTrue(total > 0); Assert.AreEqual(total, lookQuery.Search().TotalItemCount); }
public void BeforeIndexing_CancelFirstTwo() { var searchingContext = TestHelper.GetSearchingContext(); var counter = 0; var beforeIndexing = new Action <IndexingContext>( x => { counter++; if (counter != 3) { x.Cancel(); } }); var tag = new LookTag(Guid.NewGuid().ToString("N")); var lookQuery = new LookQuery(TestHelper.GetSearchingContext()) { TagQuery = new TagQuery() { Has = tag } }; Assert.IsTrue(lookQuery.Search().TotalItemCount == 0); var tags = new[] { tag }; TestHelper.IndexThings( new [] { new Thing() { Name = "First", Tags = tags }, new Thing() { Name = "Second", Tags = tags }, new Thing() { Name = "Third", Tags = tags } }, beforeIndexing); lookQuery.SearchingContext = TestHelper.GetSearchingContext(); // reset the context (to take into account new things indexed) var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.TotalItemCount == 1); Assert.AreEqual("Third", lookResult.Matches.First().Name); }
/// <summary> /// /// </summary> /// <param name="searcherName"></param> /// <param name="sort"></param> /// <param name="skip"></param> /// <param name="take"></param> /// <returns></returns> internal static MatchesResult GetNodeTypeMatches(string searcherName, PublishedItemType nodeType, string sort, int skip, int take) { var matchesResult = new MatchesResult(); var lookQuery = new LookQuery(searcherName); lookQuery.NodeQuery = new NodeQuery() { Type = nodeType }; QueryService.SetSort(lookQuery, sort); var lookResult = lookQuery.Search(); matchesResult.TotalItemCount = lookResult.TotalItemCount; matchesResult.Matches = lookResult .Matches .Skip(skip) .Take(take) .Select(x => (MatchesResult.Match)x) .ToArray(); return(matchesResult); }
/// <summary> /// /// </summary> /// <param name="searcherName"></param> /// <param name="sort"></param> /// <param name="skip"></param> /// <param name="take"></param> /// <returns></returns> internal static MatchesResult GetLocationMatches(string searcherName, string filter, string sort, int skip, int take) { var matchesResult = new MatchesResult(); var lookQuery = new LookQuery(searcherName); lookQuery.LocationQuery = new LocationQuery(); if (!string.IsNullOrWhiteSpace(filter)) { lookQuery.NodeQuery = new NodeQuery() { Alias = filter }; } QueryService.SetSort(lookQuery, sort); var lookResult = lookQuery.Search(); matchesResult.TotalItemCount = lookResult.TotalItemCount; matchesResult.Matches = lookResult .Matches .Skip(skip) .Take(take) .Select(x => (MatchesResult.Match)x) .ToArray(); return(matchesResult); }
/// <summary> /// /// </summary> /// <param name="searcherName"></param> /// <param name="nodeType"></param> /// <param name="sort"></param> /// <param name="skip"></param> /// <param name="take"></param> /// <returns></returns> internal static MatchesResult GetDetachedMatches(string searcherName, PublishedItemType nodeType, string filter, string sort, int skip, int take) { var matchesResult = new MatchesResult(); var lookQuery = new LookQuery(searcherName) { NodeQuery = new NodeQuery() { Type = nodeType, Alias = !string.IsNullOrWhiteSpace(filter) ? filter : null, DetachedQuery = DetachedQuery.OnlyDetached } }; QueryService.SetSort(lookQuery, sort); var lookResult = lookQuery.Search(); matchesResult.TotalItemCount = lookResult.TotalItemCount; matchesResult.Matches = lookResult .Matches .Skip(skip) .Take(take) .Select(x => (MatchesResult.Match)x) .ToArray(); return(matchesResult); }
internal static FiltersResult GetTagFilters(string searcherName, string tagGroup, string tagName) { var filtersResult = new FiltersResult(); var lookQuery = new LookQuery(searcherName) { TagQuery = new TagQuery() }; if (!string.IsNullOrWhiteSpace(tagGroup) && string.IsNullOrWhiteSpace(tagName)) // only have the group to query { //use raw query looking for newly indexed field(in look 0.33.0) // TODO: update look to handle tags like "colour:*" lookQuery.RawQuery = "Look_TagGroup_" + tagGroup + ":1"; } else if (!string.IsNullOrWhiteSpace(tagName)) // we have a specifc tag { lookQuery.TagQuery.Has = new LookTag(tagGroup, tagName); } filtersResult.Aliases = lookQuery .Search() .Matches .Select(x => x.Alias) .Distinct() .OrderBy(x => x) .ToArray(); return(filtersResult); }
/// <summary> /// get a chunk of matches /// </summary> /// <param name="searcherName"></param> /// <param name="tagGroup"></param> /// <param name="tagName"></param> /// <param name="sort"></param> /// <returns></returns> internal static MatchesResult GetTagMatches(string searcherName, string tagGroup, string tagName, string sort, int skip, int take) { var matchesResult = new MatchesResult(); var lookQuery = new LookQuery(searcherName); var tagQuery = new TagQuery(); // setting a tag query, means only items that have tags will be returned if (!string.IsNullOrWhiteSpace(tagGroup) && string.IsNullOrWhiteSpace(tagName)) // only have the group to query { // TODO: add a new field into the lucene index (would avoid additional query to first look up the tags in this group) var tagsInGroup = QueryService.GetTags(searcherName, tagGroup).Select(x => x.Key).ToArray(); tagQuery.HasAny = tagsInGroup; } else if (!string.IsNullOrWhiteSpace(tagName)) // we have a specifc tag { tagQuery.Has = new LookTag(tagGroup, tagName); } lookQuery.TagQuery = tagQuery; QueryService.SetSort(lookQuery, sort); var lookResult = lookQuery.Search(); matchesResult.TotalItemCount = lookResult.TotalItemCount; matchesResult.Matches = lookResult .SkipMatches(skip) .Take(take) .Select(x => (MatchesResult.Match)x) .ToArray(); return(matchesResult); }
/// <summary> /// Get a distinct collection of cultures /// </summary> /// <param name="searcherName"></param> /// <returns></returns> internal static CultureInfo[] GetCultures(string searcherName) { var cultures = new List <CultureInfo>(); var languages = ApplicationContext.Current?.Services.LocalizationService.GetAllLanguages().ToArray(); if (languages != null && languages.Any()) { var lookQuery = new LookQuery(searcherName) { NodeQuery = new NodeQuery() }; foreach (var culture in languages.Select(x => x.CultureInfo)) { lookQuery.NodeQuery.Culture = culture; if (lookQuery.Search().TotalItemCount > 0) { cultures.Add(culture); } } } return(cultures.ToArray()); }
/// <summary> /// Get matches by culture - all content has a culture set in Umbraco /// </summary> /// <param name="searcherName"></param> /// <param name="lcid"></param> /// <param name="sort"></param> /// <param name="skip"></param> /// <param name="take"></param> /// <returns></returns> internal static MatchesResult GetCultureMatches(string searcherName, int?lcid, string sort, int skip, int take) { var matchesResult = new MatchesResult(); var lookQuery = new LookQuery(searcherName) { NodeQuery = new NodeQuery() }; if (lcid.HasValue) { lookQuery.NodeQuery.Culture = new CultureInfo(lcid.Value); } else // no culture suppled, so get all content { lookQuery.NodeQuery.Type = PublishedItemType.Content; } QueryService.SetSort(lookQuery, sort); var lookResult = lookQuery.Search(); matchesResult.TotalItemCount = lookResult.TotalItemCount; matchesResult.Matches = lookResult .Matches .Skip(skip) .Take(take) .Select(x => (MatchesResult.Match)x) .ToArray(); return(matchesResult); }
public void New_Query_No_Clauses_Not_Compiled() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); var lookResult = lookQuery.Search(); Assert.IsNull(lookQuery.Compiled); }
public void Empty_Query() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsFalse(lookResult.Success); Assert.IsTrue(lookResult.TotalItemCount == 0); }
public void Boundary_Exclusive() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.DateQuery = new DateQuery(); lookQuery.DateQuery.After = new DateTime(2000, 1, 10); lookQuery.DateQuery.Boundary = DateBoundary.Exclusive; Assert.AreEqual(3, lookQuery.Search().TotalItemCount); }
public void Boundary_All() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.LocationQuery = new LocationQuery() { Boundary = new LocationBoundary(new Location(40, -75), new Location(56, 12.6)) }; Assert.AreEqual(4, lookQuery.Search().TotalItemCount); }
public void Boundary_London() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.LocationQuery = new LocationQuery() { Boundary = new LocationBoundary(new Location(52, -1), new Location(50, 0.3)) }; Assert.AreEqual(1, lookQuery.Search().TotalItemCount); }
public void Is_And_Ends_With() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); lookQuery.NameQuery.Is = "123"; lookQuery.NameQuery.EndsWith = "23"; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.TotalItemCount > 0); }
public void Conflicting_Query_Is_And_Starts_With() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); lookQuery.NameQuery.Is = "123"; lookQuery.NameQuery.StartsWith = "xyz"; var lookResult = lookQuery.Search(); Assert.IsFalse(lookResult.Success); }
public void Query_With_Node_Type_Clause() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NodeQuery = new NodeQuery(); lookQuery.NodeQuery.TypeAny = new PublishedItemType[] { PublishedItemType.Content }; var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); }
public void All_Fields() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.RequestFields = RequestFields.AllFields; lookQuery.RawQuery = $"+{TEST_FIELD}:Not_Look_Value"; var lookResult = lookQuery.Search(); Assert.AreEqual(1, lookResult.TotalItemCount); Assert.IsTrue(lookResult.Single().Fields.ContainsKey(TEST_FIELD)); }
public void Is() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); lookQuery.NameQuery.Is = "123"; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.IsTrue(lookResult.TotalItemCount == 1); Assert.AreEqual("123", (lookResult.Matches.First()).Name); }
public void New_Query_Executed_To_Make_Compiled() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()) { NodeQuery = new NodeQuery() { Alias = "thing" } }; var lookResult = lookQuery.Search(); Assert.IsNotNull(lookQuery.Compiled); }
public void Has_All() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TagQuery = new TagQuery() { HasAll = TagQuery.MakeTags("shape:circle") }; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.AreEqual(3, lookResult.TotalItemCount); }
public void Has() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TagQuery = new TagQuery() { Has = new LookTag("shape") }; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.AreEqual(9, lookResult.TotalItemCount); }
public void Max_Results_Value_Valid() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); // set a query clause so it's acutally executed lookQuery.MaxResults = 5; var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); Assert.AreEqual(100, lookResult.TotalItemCount); Assert.AreEqual(5, lookResult.Matches.Count()); }
public void Max_Results_Value_Invalid_Negative() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); // set a query clause so it's acutally executed lookQuery.MaxResults = -1; // set an invalid value - this should be ignored and default back to 5000 var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); Assert.AreEqual(100, lookResult.TotalItemCount); Assert.AreEqual(100, lookResult.Matches.Count()); }
public void Max_Results_Configuration_Value_Valid() { LookConfiguration.MaxResults = 3; // set first so that new lookQuerys will default to using this value var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.NameQuery = new NameQuery(); // set a query clause so it's acutally executed var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); Assert.AreEqual(100, lookResult.TotalItemCount); Assert.AreEqual(3, lookResult.Matches.Count()); }
public void Has_Any_And_Empty_Inner_Collections() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TagQuery = new TagQuery() { Has = new LookTag("shape"), // HACK: need to clear index on startup of this class HasAnyAnd = new LookTag[][] { new LookTag[] { } } }; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.AreEqual(9, lookResult.TotalItemCount); }
public void Not() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TagQuery = new TagQuery() { Has = new LookTag("shape"), // HACK: need to clear index on startup of this class Not = new LookTag("shape", "circle") }; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.AreEqual(6, lookResult.TotalItemCount); }
public void Query_Apply_Random_Facet_Then_Re_Query() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TagQuery = new TagQuery(); lookQuery.TagQuery.HasAll = new LookTag[] { _red }; lookQuery.TagQuery.FacetOn = new TagFacetQuery(_colour); // first query var lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); Assert.IsTrue(lookResult.TotalItemCount == 7); Assert.IsTrue(lookResult.Facets.Length == 7); // pick a random facet var random = new Random(); var facet = lookResult .Facets .OrderBy(x => random.Next()) .First(); // get the expected count var facetCount = facet.Count; // apply facet to query lookQuery.ApplyFacet(facet); // second query lookResult = lookQuery.Search(); Assert.IsNotNull(lookResult); Assert.IsTrue(lookResult.Success); Assert.AreEqual(facetCount, lookResult.TotalItemCount); }
public void Highlighting() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.TextQuery = new TextQuery() { SearchText = "dolor", GetHighlight = true }; var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.IsTrue(lookResult.TotalItemCount > 0); Assert.IsFalse(string.IsNullOrWhiteSpace(lookResult.Matches.First().Highlight.ToString())); }
public void Max_Distance() { var lookQuery = new LookQuery(TestHelper.GetSearchingContext()); lookQuery.LocationQuery = new LocationQuery(); lookQuery.LocationQuery.Location = _london; lookQuery.LocationQuery.MaxDistance = new Distance(300, DistanceUnit.Miles); var lookResult = lookQuery.Search(); Assert.IsTrue(lookResult.Success); Assert.IsTrue(lookResult.TotalItemCount == 2); Assert.IsTrue(lookResult.Matches.Any(x => x.Location.Equals(_london))); Assert.IsTrue(lookResult.Matches.Any(x => x.Location.Equals(_paris))); }