public void AddIndex(DataIndex data) { dataIndexes.Add(data); // export save file Save(); }
public static Uri GetUri(this DataIndex index) { var uri = Properties.Settings.Default.NewsHostUri; var ministry = index as Ministry; if (ministry != null) { if (index.Key != "office-of-the-premier") { uri = AppendUriSegment(uri, "ministries"); if (ministry.ParentMinistryKey != null) { uri = AppendUriSegment(uri, UrlEncoder.Default.Encode(ministry.ParentMinistryKey)); } } } else if (index.Kind == "tags" && index.Key == "speeches") { uri = AppendUriSegment(uri, "office-of-the-premier"); } else { var kind = index.Kind == "tags" ? "news-subscribe" : index.Kind; // use news-subscribe as an alias for tags uri = AppendUriSegment(uri, kind); } uri = AppendUriSegment(uri, UrlEncoder.Default.Encode(index.Key)); return(uri); }
public void Query_On_Document_That_Does_Not_Have_High_Enough_Word_Frequency() { using (var store = GetDocumentStore()) { const string key = "datas/4-A"; using (var session = store.OpenSession()) { new DataIndex().Execute(store); var list = GetDataList(); list.ForEach(session.Store); session.SaveChanges(); WaitForIndexing(store); } using (var session = store.OpenSession()) { var indexName = new DataIndex().IndexName; var list = session.Advanced.MoreLikeThis <Data>(new MoreLikeThisQuery() { Query = $"FROM INDEX '{indexName}'", DocumentId = key, Fields = new[] { "Body" } }); WaitForIndexing(store); Assert.Empty(list); } } }
public static void AddFeaturePostKeyToLoad(DataIndex index, IList <string> postKeys) { if (index.FeaturePostKey != null) { postKeys.Insert(0, index.FeaturePostKey); } }
public static void RemoveData(string name) { if (DataIndex.Find(name) is Data t) { RemoveData(t); } }
public void Query_On_Document_That_Does_Not_Have_High_Enough_Word_Frequency() { using (var store = GetDocumentStore()) { const string key = "datas/4-A"; using (var session = store.OpenSession()) { new DataIndex().Execute(store); var list = GetDataList(); list.ForEach(session.Store); session.SaveChanges(); WaitForIndexing(store); } using (var session = store.OpenSession()) { var indexName = new DataIndex().IndexName; var list = session.Query <Data>(indexName) .MoreLikeThis(f => f.UsingDocument(x => x.Id == key).WithOptions(new MoreLikeThisOptions { MinimumDocumentFrequency = 5, MinimumTermFrequency = 2, Fields = new[] { "Body" } })) .ToList(); WaitForIndexing(store); Assert.Empty(list); } } }
public static async Task <IEnumerable <Post> > LoadTopAndFeaturePosts(DataIndex index, Repository repository) { List <string> postKeys = new List <string>(); AddTopPostKeyToLoad(index, postKeys); AddFeaturePostKeyToLoad(index, postKeys); return(await repository.GetPostsAsync(postKeys)); }
private Func <Post, bool> GetIndexFilter(DataIndex index) { if (index.Kind == "sectors") { return(SectorFilter(index.Key)); } return(null); }
public static void RemoveData(Data d) { if (DataIndex.Contains(d)) { DataIndex.Remove(d); d.ClearCategories(); } }
/// <summary> /// This event is fired AFTER the dataIndex is parsed. /// </summary> /// <param name="xmlNode"></param> /// <param name="dataIndex"></param> /// <returns>True if cancelled else false if not.</returns> public bool Parsed(XmlNode xmlNode, ref DataIndex dataIndex) { // initial value bool cancel = false; // Add any post processing code here. Set cancel to true to abort adding this object. // return value return(cancel); }
//////////////////////////////////////////////////////////////////////// public int GetInt(DataIndex index) { DataElementBase result; if (m_DataBase.TryGetValue(index, out result)) { return(result.GetInt()); } return(default);
private async Task <HomeViewModel> GetMoreArticlesModel(DataIndex dataIndex, string postKind, int skipCount) { var latestNews = await Repository.GetLatestPostsAsync(dataIndex, ProviderHelpers.MaximumLatestNewsItemsLoadMore, postKind, GetIndexFilter(dataIndex), skipCount); var model = new IndexModel(dataIndex, latestNews); return(new HomeViewModel() { IndexModel = model }); }
public void ReplaceIndex(DataIndex data) { int findId = dataIndexes.FindIndex(x => x.key == data.key); if (findId != -1 && findId < dataIndexes.Count) { dataIndexes[findId] = data; } // export save file Save(); }
public async Task <HomeViewModel> GetHomePosts(string postKind) { DataIndex homeIndex = await Repository.GetHomeAsync(); if (homeIndex == null) { return(null); } int count = ProviderHelpers.MaximumLatestNewsItemsLoadMore + ProviderHelpers.MaximumLatestNewsItems; var latestNews = await Repository.GetLatestPostsAsync(homeIndex, count, postKind); var model = new HomeViewModel() { IndexModel = new IndexModel(homeIndex, latestNews) }; if (string.IsNullOrEmpty(postKind)) { model.Title = "Home"; model.FeedUri = ProviderHelpers.Uri(new Uri(Configuration["NewsHostUri"]), "feed"); await LoadAsync(model, new List <IndexModel> { model.IndexModel }); model.SlideItems = await Repository.GetSlidesAsync(); //await LoadSectors(model); //await ProviderHelpers.LoadMediaAssets(model); } else { model.Title = Char.ToUpper(postKind[0]) + postKind.Substring(1); if (model.Title == "Factsheets") { model.Title = model.Title + " & Opinion Editorials"; } model.FeedUri = ProviderHelpers.Uri(new Uri(Configuration["NewsHostUri"]), postKind + "/" + "feed"); await LoadAsync(model); } //model.MoreNewsUri = ProviderHelpers.Uri(Properties.Settings.Default.NewsHostUri, "releases/archive"); model.Footer = await GetFooter(null); return(model); }
/// <summary> /// Get the next count posts of type postKind for the specified index (newsroom or category) /// </summary> /// <param name="indexModel">home or one of categories</param> /// <param name="postKind">One of: releases, stories, factsheets, updates or default (releases+stories except top/feature)</param> /// <param name="skip">number of posts to skip</param> /// <returns></returns> public async Task <IEnumerable <Post> > GetLatestPostsAsync(IndexModel indexModel, string postKind = null, int skip = 0) { int count = ProviderHelpers.MaximumLatestNewsItemsLoadMore; if (skip == 0) { count += ProviderHelpers.MaximumLatestNewsItems; } DataIndex index = indexModel.Index; if (postKind == null) { int latestNewsCount = indexModel.LatestNews.Count(); if (latestNewsCount > skip) { return(indexModel.LatestNews.Skip(skip).Take(count)); } if (skip != latestNewsCount) { _logger.LogError("skip ({0})/count({1}) mismatch in GetLatestPostsAsync({2})!", skip, latestNewsCount, index.Key); } } IList <Post> posts = await ApiClient.Posts.GetLatestAsync(index.Kind, index.Key, APIVersion, postKind, count, skip); if (postKind != null) { return(posts); } IDictionary <string, object> cacheForType = _cache[typeof(Post)]; lock (cacheForType) { foreach (Post post in posts) { object cachedPost; if (!cacheForType.TryGetValue(post.Key, out cachedPost)) { if (skip < MAX_NUM_CACHED_POSTS_PER_INDEX) { cacheForType.Add(post.Key, post); } cachedPost = post; } indexModel.LatestNews.Add((Post)cachedPost); // use the post already in cache instead of the newly downloaded (for memory reuse) } } return(indexModel.LatestNews.Skip(skip).Take(count)); }
public void AddKey(DataIndex index, Vector2 value) { if (m_DataBase.ContainsKey(index)) { return; } var dataElement = new DataElementBase() { m_Data = new Vector2?(value) }; m_DataBase.Add(index, dataElement); }
public void AddKey(DataIndex index, object value) { if (m_DataBase.ContainsKey(index)) { return; } var dataElement = new DataElementBase() { m_Data = value }; m_DataBase.Add(index, dataElement); }
public void Can_Use_Boost_Param() { using (var store = GetDocumentStore()) { const string key = "datas/1-A"; using (var session = store.OpenSession()) { new DataIndex().Execute(store); var list = new List <Data> { new Data { Body = "This is a test. it is a great test. I hope I pass my great test!" }, new Data { Body = "Cake is great." }, new Data { Body = "I have a test tomorrow." } }; list.ForEach(session.Store); session.SaveChanges(); WaitForIndexing(store); } using (var session = store.OpenSession()) { var indexName = new DataIndex().IndexName; var list = session.Advanced.MoreLikeThis <Data>( new MoreLikeThisQuery() { Query = $"FROM INDEX '{indexName}'", DocumentId = key, Fields = new[] { "Body" }, MinimumWordLength = 3, MinimumDocumentFrequency = 1, Boost = true }); Assert.NotEqual(0, list.Count); Assert.Equal("I have a test tomorrow.", list[0].Body); } } }
public static Element Find(string name) { var temp = DataIndex.Find(name); if (temp != null) { return(temp); } temp = Images.Find(name); if (temp != null) { return(temp); } return(Root.Find(name)); }
public void Can_Use_Min_Doc_Freq_Param() { using (var store = GetDocumentStore()) { const string key = "datas/1-A"; using (var session = store.OpenSession()) { new DataIndex().Execute(store); var list = new List <Data> { new Data { Body = "This is a test. Isn't it great? I hope I pass my test!" }, new Data { Body = "I have a test tomorrow. I hate having a test" }, new Data { Body = "Cake is great." }, new Data { Body = "This document has the word test only once" } }; list.ForEach(session.Store); session.SaveChanges(); WaitForIndexing(store); } using (var session = store.OpenSession()) { var indexName = new DataIndex().IndexName; var list = session.Advanced.MoreLikeThis <Data>(new MoreLikeThisQuery() { Query = $"FROM INDEX '{indexName}'", DocumentId = key, Fields = new[] { "Body" }, MinimumDocumentFrequency = 2 }); Assert.NotEmpty(list); } } }
/// <summary> /// Get the next count posts of type postKind for the specified index (newsroom or category) /// </summary> /// <param name="indexModel">home or one of categories</param> /// <param name="count">number of posts to get</param> /// <param name="postKind">One of: releases, stories, factsheets, updates or default (releases+stories except top/feature)</param> /// <param name="categoryFilter">filter on Ministry, Sector, Themes, Service or Tag</param> /// <param name="skip">number of posts to skip (ignoring top/feature posts</param> /// <returns></returns> public async Task <IEnumerable <Post> > GetLatestPostsAsync(DataIndex index, int count, string postKind = null, Func <Post, bool> categoryFilter = null, int skip = 0) { int postCountB4ApiCall; IEnumerable <Post> filteredPosts; IDictionary <string, object> cacheForPosts = _cache[typeof(Post)]; lock (cacheForPosts) { postCountB4ApiCall = cacheForPosts.Count(); var postKindFilter = postKind != null ? p => p.Kind == postKind : (Func <Post, bool>)(p => p.Kind == "releases" || p.Kind == "stories"); filteredPosts = cacheForPosts.Select(p => (Post)p.Value).Where(postKindFilter).ToList(); } bool cacheClearHappenedWhileUserIsBrowsingOldReleases = skip > filteredPosts.Count(); bool canBeCached = (postKind == null || postKind == "factsheets") && categoryFilter == null && postCountB4ApiCall < NUM_CACHED_POSTS && !cacheClearHappenedWhileUserIsBrowsingOldReleases; int skipToAsk = canBeCached ? filteredPosts.Count() : skip; if (postKind == null) { filteredPosts = filteredPosts.Where(p => p.Key != index.TopPostKey && p.Key != index.FeaturePostKey); } if (categoryFilter != null) { filteredPosts = filteredPosts.Where(categoryFilter).ToList(); } bool useCache = skip + count <= filteredPosts.Count(); // enough posts in the cache to use it? IEnumerable <Post> fetchedPosts = null; if ((canBeCached || !useCache) && apiConnected) { // Ask for more when we can cache it. int countToAsk = canBeCached ? ProviderHelpers.MaximumLatestNewsItemsLoadMore * 5 : count; fetchedPosts = await ApiClient.Posts.GetLatestAsync(index.Kind, index.Key, APIVersion, postKind, countToAsk, skipToAsk); if (canBeCached) { CacheLatestPosts(fetchedPosts, cacheForPosts, postCountB4ApiCall); // we also cache top/feature posts (sorted by PublishDate) if (!useCache) { fetchedPosts = fetchedPosts.Where(p => p.Key != index.TopPostKey && p.Key != index.FeaturePostKey); } } } return((useCache || fetchedPosts == null ? filteredPosts.Skip(skip) : fetchedPosts).Take(count)); }
protected Func <Post, bool> GetIndexFilter(DataIndex index) { switch (index.Kind) { case "ministries": return(MinistryFilter(index.Key));; case "sectors": return(SectorFilter(index.Key));; case "themes": return(ThemeFilter(index.Key));; case "tags": return(TagFilter(index.Key));; } return(null); }
// ===== INDEX DATA ===== public void SaveIndexData(Panel panel) { string key = panel.GetTitle(); ColorBar.ColorType colorType = panel.GetColorType(); DataIndex newData = new DataIndex(key, (int)colorType); // replace already have data if (dataIndexer.IsContain(key)) { dataIndexer.ReplaceIndex(newData); } // add new data else { dataIndexer.AddIndex(newData); } }
private void ProcessNeg() { if (stack.Count > 0) { if (stack.Peek() is DataIndex) { DataIndex stackTop = (DataIndex)stack.Pop(); stackTop.IsNegative = !stackTop.IsNegative; stack.Push(stackTop); } else { var expressionSyntax = stack.Pop() as ExpressionSyntax; expressionSyntax = SyntaxFactory.ParenthesizedExpression(expressionSyntax); expressionSyntax = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.UnaryMinusExpression, expressionSyntax); stack.Push(expressionSyntax); } } }
/*public async Task LoadSectors(HomeViewModel model) * { * using (Profiler.StepStatic("Loading Sectors")) * { * model.PostSectors = new Dictionary<Post, IEnumerable<Category>>(); * if (model.TopStory != null) * { * IEnumerable<Category> sectors = await Repository.GetPostSectorsAsync(model.TopStory); * model.PostSectors.Add(model.TopStory, sectors); * } * * IEnumerable<Category> postSectors = null; * if (model.FeatureStory != null && !model.PostSectors.TryGetValue(model.FeatureStory, out postSectors)) * { * postSectors = await Repository.GetPostSectorsAsync(model.FeatureStory); * model.PostSectors.Add(model.FeatureStory, postSectors); * } * * if (model.LatestNews != null) * { * foreach (Post post in model.LatestNews) * { * if (!model.PostSectors.TryGetValue(post, out postSectors)) * { * postSectors = await Repository.GetPostSectorsAsync(post); * model.PostSectors.Add(post, postSectors); * } * } * } * } * }*/ private async Task <SyndicationFeedViewModel> GetFeedModel(string key, string postKind) { DataIndex index = await GetDataIndex(key, (string)RouteData.Values["category"]); if (index == null) { return(null); } var model = new SyndicationFeedViewModel(); model.AlternateUri = new Uri(Configuration["NewsHostUri"]); var posts = new List <Post>(); if (string.IsNullOrEmpty(postKind)) { model.Title = index.Name; var loadedPosts = await IndexModel.LoadTopAndFeaturePosts(index, Repository); var topPost = loadedPosts.SingleOrDefault(p => p.Key == index.TopPostKey); if (topPost != null) { posts.Add(topPost); } var featurePost = loadedPosts.SingleOrDefault(p => p.Key == index.FeaturePostKey); if (featurePost != null) { posts.Add(featurePost); } } else { model.Title = index.Name + " " + char.ToUpper(postKind[0]) + postKind.Substring(1); } posts.AddRange(await Repository.GetLatestPostsAsync(index, ProviderHelpers.MaximumSyndicationItems - posts.Count, postKind, GetIndexFilter(index))); model.Entries = posts; return(model); }
public void VerifyReversibilityOfElementsAsString() { var d = new DataIndex { ElementsAsString = "Field" }; Assert.AreEqual("Field", d.ElementsAsString); Assert.AreEqual(1, d.Elements.SafeCount()); var firstElement = d.Elements.First(); Assert.AreEqual("Field", firstElement.FieldPath); Assert.AreEqual(false, firstElement.DescendingOrder); Assert.IsNull(firstElement.Function); d = new DataIndex { ElementsAsString = "Field2:-" }; Assert.AreEqual("Field2:-", d.ElementsAsString); Assert.AreEqual(1, d.Elements.SafeCount()); firstElement = d.Elements.First(); Assert.AreEqual("Field2", firstElement.FieldPath); Assert.AreEqual(true, firstElement.DescendingOrder); Assert.IsNull(firstElement.Function); d = new DataIndex { ElementsAsString = "DateOfPurchase:+:Day|Buyer.Id" }; Assert.AreEqual("DateOfPurchase:+:Day|Buyer.Id", d.ElementsAsString); Assert.AreEqual(2, d.Elements.SafeCount()); firstElement = d.Elements.First(); Assert.AreEqual("DateOfPurchase", firstElement.FieldPath); Assert.AreEqual(false, firstElement.DescendingOrder); Assert.AreEqual("Day", firstElement.Function); var secondElement = d.Elements.Skip(1).First(); Assert.AreEqual("Buyer.Id", secondElement.FieldPath); Assert.AreEqual(false, secondElement.DescendingOrder); Assert.IsNull(secondElement.Function); }
private ExpressionSyntax GetVariableExpression(DataIndex dataIndex) { short variable = dataIndex.Value; ExpressionSyntax expressionSyntax = null; //if not static condition is the variable itself if (!VariableSet.Variables[variable].Static) { expressionSyntax = SyntaxFactory.IdentifierName(VariableSet.Variables[variable].Name); if (dataIndex.IsNegative) { expressionSyntax = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.UnaryMinusExpression, expressionSyntax); } } else { var dataType = VariableSet.Variables[variable].DataType; if (dataType == "String") { object objValue = VariableSet.GetCurrentValue(variable); string value = (string)objValue; //value = value.ToString(); //value = value.Replace("\"", ""); //SyntaxTriviaList syntaxTriviaList = new SyntaxTriviaList(); var syntaxToken = SyntaxFactory.ParseToken("\"" + value + "\""); //syntaxToken = SyntaxFactory.Literal(syntaxTriviaList, value, syntaxTriviaList, expressionSyntax = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, syntaxToken); } else if (dataType == "Float") { //Double float value = float.Parse(VariableSet.GetCurrentValue(variable).ToString().Replace("\"", "").Replace(@"\", "")); if (dataIndex.IsNegative) { value = value * -1; } expressionSyntax = SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value)); // cope with -0 !!! if (value == 0 && dataIndex.IsNegative) { expressionSyntax = SyntaxFactory.PrefixUnaryExpression(SyntaxKind.UnaryMinusExpression, expressionSyntax); } } else if (dataType == "Int") { int value = int.Parse(VariableSet.GetCurrentValue(variable).ToString().Replace("\"", "").Replace(@"\", "")); if (dataIndex.IsNegative) { value = value * -1; } expressionSyntax = SyntaxFactory.LiteralExpression(SyntaxKind.NumericLiteralExpression, SyntaxFactory.Literal(value)); } else if (dataType == "Character") { string value = (string)VariableSet.GetCurrentValue(variable).ToString().Replace("\"", ""); if (value == "Me" || value == "Player") { expressionSyntax = SyntaxFactory.IdentifierName(value); } else { expressionSyntax = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(value)); } } else if (dataType == "Point") { string value = (string)VariableSet.GetCurrentValue(variable).ToString().Replace("\"", ""); expressionSyntax = SyntaxFactory.LiteralExpression(SyntaxKind.StringLiteralExpression, SyntaxFactory.Literal(value)); } else { throw (new NotImplementedException()); } } return(expressionSyntax); }
// <Summary> // This method is used to export a DataIndex object to xml. // </Summary> public string ExportDataIndex(DataIndex dataIndex, int indent = 0) { // initial value string dataIndexXml = ""; // locals string indentString = TextHelper.Indent(indent); string indentString2 = TextHelper.Indent(indent + 2); // If the dataIndex object exists if (NullHelper.Exists(dataIndex)) { // Create a StringBuilder StringBuilder sb = new StringBuilder(); // Append the indentString sb.Append(indentString); // Write the open dataIndex node sb.Append("<DataIndex>" + Environment.NewLine); // Write out each property // Write out the value for AllowPageLocks sb.Append(indentString2); sb.Append("<AllowPageLocks>" + dataIndex.AllowPageLocks + "</AllowPageLocks>" + Environment.NewLine); // Write out the value for AllowRowLocks sb.Append(indentString2); sb.Append("<AllowRowLocks>" + dataIndex.AllowRowLocks + "</AllowRowLocks>" + Environment.NewLine); // Write out the value for Clustered sb.Append(indentString2); sb.Append("<Clustered>" + dataIndex.Clustered + "</Clustered>" + Environment.NewLine); // Write out the value for DataSpaceId sb.Append(indentString2); sb.Append("<DataSpaceId>" + dataIndex.DataSpaceId + "</DataSpaceId>" + Environment.NewLine); // Write out the value for FillFactor sb.Append(indentString2); sb.Append("<FillFactor>" + dataIndex.FillFactor + "</FillFactor>" + Environment.NewLine); // Write out the value for FilterDefinition sb.Append(indentString2); sb.Append("<FilterDefinition>" + dataIndex.FilterDefinition + "</FilterDefinition>" + Environment.NewLine); // Write out the value for HasFilter sb.Append(indentString2); sb.Append("<HasFilter>" + dataIndex.HasFilter + "</HasFilter>" + Environment.NewLine); // Write out the value for IgnoreDuplicateKey sb.Append(indentString2); sb.Append("<IgnoreDuplicateKey>" + dataIndex.IgnoreDuplicateKey + "</IgnoreDuplicateKey>" + Environment.NewLine); // Write out the value for IndexType sb.Append(indentString2); sb.Append("<IndexType>" + dataIndex.IndexType + "</IndexType>" + Environment.NewLine); // Write out the value for IsDisabled sb.Append(indentString2); sb.Append("<IsDisabled>" + dataIndex.IsDisabled + "</IsDisabled>" + Environment.NewLine); // Write out the value for IsHypothetical sb.Append(indentString2); sb.Append("<IsHypothetical>" + dataIndex.IsHypothetical + "</IsHypothetical>" + Environment.NewLine); // Write out the value for IsPadded sb.Append(indentString2); sb.Append("<IsPadded>" + dataIndex.IsPadded + "</IsPadded>" + Environment.NewLine); // Write out the value for IsPrimary sb.Append(indentString2); sb.Append("<IsPrimary>" + dataIndex.IsPrimary + "</IsPrimary>" + Environment.NewLine); // Write out the value for IsUnique sb.Append(indentString2); sb.Append("<IsUnique>" + dataIndex.IsUnique + "</IsUnique>" + Environment.NewLine); // Write out the value for IsUniqueConstraint sb.Append(indentString2); sb.Append("<IsUniqueConstraint>" + dataIndex.IsUniqueConstraint + "</IsUniqueConstraint>" + Environment.NewLine); // Write out the value for Name sb.Append(indentString2); sb.Append("<Name>" + dataIndex.Name + "</Name>" + Environment.NewLine); // Write out the value for TypeDescription sb.Append(indentString2); sb.Append("<TypeDescription>" + dataIndex.TypeDescription + "</TypeDescription>" + Environment.NewLine); // Append the indentString sb.Append(indentString); // Write out the close dataIndex node sb.Append("</DataIndex>" + Environment.NewLine); // set the return value dataIndexXml = sb.ToString(); } // return value return(dataIndexXml); }
public void Can_Use_Stop_Words() { using (var store = GetDocumentStore()) { const string key = "datas/1-A"; using (var session = store.OpenSession()) { new DataIndex().Execute(store); var list = new List <Data> { new Data { Body = "This is a test. Isn't it great? I hope I pass my test!" }, new Data { Body = "I should not hit this document. I hope" }, new Data { Body = "Cake is great." }, new Data { Body = "This document has the word test only once" }, new Data { Body = "test" }, new Data { Body = "test" }, new Data { Body = "test" }, new Data { Body = "test" } }; list.ForEach(session.Store); session.Store(new StopWordsSetup { Id = "Config/Stopwords", StopWords = new List <string> { "I", "A", "Be" } }); session.SaveChanges(); WaitForIndexing(store); } using (var session = store.OpenSession()) { var indexName = new DataIndex().IndexName; var list = session.Advanced.MoreLikeThis <Data>(new MoreLikeThisQuery() { Query = $"FROM INDEX '{indexName}'", DocumentId = key, StopWordsDocumentId = "Config/Stopwords", MinimumDocumentFrequency = 1 }); Assert.Equal(5, list.Count()); } } }
private List <DataIndex> _generateNCIndexes1D(ucar.ma2.Array sourceData, ucar.ma2.Array xData, ucar.ma2.Array yData, ucar.ma2.Index xIndex, ucar.ma2.Index yIndex, int[] resShape, int xPosition, int yPosition, java.util.List attList, List <double> xList, List <double> yList) { //assuming that the file is 1D with the same lat. or same lon. List <DataIndex> ncIndexes = new List <DataIndex>(); ucar.ma2.Index resIndex = sourceData.getIndex(); //find closest x and y points int[] ydataShape = yData.getShape(); int[] xdataShape = xData.getShape(); int yCount = 0; //static for (int xCount = 1; xCount < (int)resShape[xPosition]; xCount++) { double latFromNC = 0; double prevLatFromNC = 0; double prevPrevLatFromNC = 0; if (ydataShape.Length == 2) { latFromNC = yData.getDouble(yIndex.set(yCount, xCount)); prevLatFromNC = yData.getDouble(yIndex.set(yCount - 1, xCount)); if (yCount >= 2) { prevPrevLatFromNC = yData.getDouble(yIndex.set(yCount - 2, xCount)); } } else if (ydataShape.Length == 1) { latFromNC = yData.getDouble(yCount); } double lonFromNC = 0; double prevLonFromNC = 0; double prevPrevLonFromNC = 0; if (xdataShape.Length == 2) { lonFromNC = xData.getDouble(xIndex.set(yCount, xCount)); prevLonFromNC = xData.getDouble(xIndex.set(yCount, xCount - 1)); if (xCount >= 2) { prevPrevLonFromNC = xData.getDouble(xIndex.set(yCount, xCount - 2)); } } else if (xdataShape.Length == 1) { lonFromNC = xData.getDouble(xCount); } int rangeCount = 0; if (latFromNC >= yList.Min()) { rangeCount++; } if (latFromNC <= yList.Max()) { rangeCount++; } if (lonFromNC >= xList.Min()) { rangeCount++; } if (lonFromNC <= xList.Max()) { rangeCount++; } DataIndex newIndex = new DataIndex(); newIndex.xIndex = xCount; newIndex.prevXIndex = xCount - 1; newIndex.yIndex = yCount; newIndex.prevYIndex = yCount - 1; newIndex.nc_X = lonFromNC; newIndex.nc_Y = latFromNC; newIndex.pnc_X = prevLonFromNC; newIndex.pnc_Y = prevLatFromNC; newIndex.data = sourceData.getDouble(resIndex.set(xCount)); newIndex.prevData = sourceData.getDouble(resIndex.set(xCount - 1)); newIndex.lonFromDfs = new List <double>(); foreach (double xPoint in xList) { if (xPoint >= prevLonFromNC && xPoint <= lonFromNC) { newIndex.lonFromDfs.Add(xPoint); } else if (xPoint >= prevPrevLonFromNC && xPoint <= lonFromNC) { newIndex.lonFromDfs.Add(xPoint); } else if (xPoint == lonFromNC) { newIndex.lonFromDfs.Add(xPoint); } } newIndex.latFromDfs = new List <double>(); foreach (double yPoint in yList) { if (yPoint >= prevLatFromNC && yPoint <= latFromNC) { newIndex.latFromDfs.Add(yPoint); } else if (yPoint >= prevPrevLatFromNC && yPoint <= latFromNC) { newIndex.latFromDfs.Add(yPoint); } else if (yPoint == latFromNC) { newIndex.latFromDfs.Add(yPoint); } } if (_util.IsValueValid(attList, newIndex.data) && rangeCount == 4) { ncIndexes.Add(newIndex); } } return(ncIndexes); }