public void SearchPerson_by_last_name_wildchar_Test() { //ARRANGE //set up a person var personId = Guid.NewGuid(); var person = PersonAggregateFactory.BuildPersonSearchModel(personId, "John", "Doe"); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); SearchClientFactory.RegisterDependencies(dependencyResolver); //create an unique index var indexId = Guid.NewGuid(); var indexName = String.Format("{0}_{1}", typeof(EsPersonSearch).Name, indexId); var indexContext = new IndexContext(typeof(EsPersonSearch), indexName); //set up document CRUD controller and create a mock document var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var documentDispatcher = new DocumentDispatcher(clientFactory, indexManager, responseHandler); var documentclient = new DocumentController(documentDispatcher, indexManager, responseHandler); try { var index = indexManager.BuildIndexName(indexContext); var context = new UpsertDocumentContext <EsPersonSearch>(personId) { Document = person, IndexContext = indexContext }; //create person document documentclient.UpsertDocument(context); Thread.Sleep(1000); var searchResponse = client .Search <EsPersonSearch>(s => s.Query(q => q.Wildcard(m => m.Field(g => g.PersonName.LastName) .Value("D*e"))) .Index(index) .Explain()); var allRecords = client .Search <EsPersonSearch>(q => q .Index(index)); //ASSERT Assert.IsTrue(searchResponse.IsValid); Assert.AreEqual(1, searchResponse.Documents.Count()); Assert.AreEqual(personId, searchResponse.Documents.First().Id); Assert.AreEqual("John", searchResponse.Documents.First().PersonName.FirstName); Assert.AreEqual("Doe", searchResponse.Documents.First().PersonName.LastName); } finally { indexManager.DeleteIndex(indexContext); } }
public void Add(Words word) { using (var ctx = new IndexContext()) { ctx.Words.Add(word); ctx.SaveChanges(); } }
public void Add(Paths path) { using (var ctx = new IndexContext()) { ctx.Paths.Add(path); ctx.SaveChanges(); } }
public UserController ( IndexContext db, IConfiguration config ) { _db = db; _configuration = config; }
public Task DeleteIndex(IndexContext indexContext) { var client = this._clientFactory.GetClient(); var index = this.BuildIndexName(indexContext); var response = client.DeleteIndex(index); this._responseHandler.ValdateAndHandleException(response, true); return(Task.CompletedTask); }
public ProductModelIndexMapping(IndexContext context) { context.Indices.Create(context.GetIndexName <ProductModel>(), c => c .Map <ProductModel>(m => m .Properties(p => p .Number(nm => nm.Name(n => n.Id).Type(NumberType.Integer)) .Text(tx => tx.Name(n => n.Name).Analyzer("keyword")) ) )); }
public async Task <IndexName> GetIndex(IndexContext indexContext) { var client = this._clientFactory.GetClient(); var index = this.BuildIndexName(indexContext); await this.BuildIndex(index); return(index); }
public WishModelIndexMapping(IndexContext context) { context.Indices.Create(context.GetIndexName <WishModel>(), c => c .Map <WishModel>(m => m .Properties(p => p .Number(nm => nm.Name(n => n.Id)) .Nested <ProductModel>(nt => nt.Name(n => n.Products)) ) ) ); }
public void Create_person_search_index() { //ARRANGE //var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}", typeof(EsPersonSearch).Name).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext <ParentTestClass>(indexName); var index = new IndexName { Name = indexName, Type = typeof(ParentTestClass) }; var indexDescriptor = new CreateIndexDescriptor(index).Mappings(map => map.Map <EsPersonSearch>(m => m.AutoMap())); // .Mappings(map => map.Map<ParentTestClass>(m => // m.Properties(p => p.Keyword(d => d.Name(n => n.Email))).AutoMap())); //var index = indexManager.BuildIndexName(indexContext); //ACT try { client.CreateIndex(indexDescriptor); //indexManager.BuildIndex(index).Wait(); //Thread.Sleep(1000); //var d = client.Get<EsPersonSearch>(new DocumentPath<EsPersonSearch>(new EsPersonSearch { Id = Guid.Parse("a8de6650-236e-46ff-b3b9-b0bb24f0a38b") }) // .Index(index)); var documents = client.Search <EsPersonSearch>(s => s.Query(q => q.MatchAll()) .Index(index)); var document = client.Search <EsPersonSearch>(s => s.Query(q => q.Match(m => m.Field(f => f.PersonName.LastName) .Query("Doe"))) .Index(index)); var indexState = indexManager.GetIndexState(indexContext); var providedName = indexState.Settings["index.provided_name"]; var propertiesMapped = indexState.Mappings.SelectMany(x => x.Value.Properties); //ASSERT Assert.AreEqual(indexName, providedName); } finally { //client.DeleteIndex(index); } }
public void MapPersonNamePropertyTests() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); SearchClientFactory.RegisterDependencies(dependencyResolver); //create an unique index var indexName = String.Format("{0}_{1}", typeof(EsPersonSearch).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext(typeof(EsPersonSearch), indexName); var index = indexManager.GetIndex(indexContext).Result; //ACT try { Thread.Sleep(1000); var indexReqiest = new GetIndexRequest(index); var indexResponse = client.GetIndex(indexReqiest); var indices = indexResponse.Indices.ToList(); var first = indices.First(); var mappings = first.Value.Mappings.Select(x => x.Value) .SelectMany(x => x.Properties, (x, y) => { return(new { y.Key, y.Value.Name, y.Value.Type, Properties = ((ObjectProperty)y.Value).Properties }); }); var nameProperty = mappings.First(x => x.Name.Name.Equals("personName", StringComparison.OrdinalIgnoreCase)); var firstNameProperty = nameProperty.Properties.First(x => x.Key.Name.Equals("firstName", StringComparison.OrdinalIgnoreCase)); var lastNameProperty = nameProperty.Properties.First(x => x.Key.Name.Equals("lastName", StringComparison.OrdinalIgnoreCase)); //ASSERT person name Assert.IsTrue(indexResponse.IsValid); Assert.AreEqual(1, indices.Count); Assert.AreEqual("object", nameProperty.Type.Name); //ASSERT person first name Assert.AreEqual("keyword", firstNameProperty.Value.Type.Name); //ASSERT person last name Assert.AreEqual("keyword", lastNameProperty.Value.Type.Name); } finally { client.DeleteIndex(index); } }
public IndexState GetIndexState(IndexContext indexContext) { var index = this.BuildIndexName(indexContext); return(this._indices.GetOrAdd(index.Name, k => { var client = this._clientFactory.GetClient(); var response = client.GetIndex(index); this._responseHandler.ValdateAndHandleException(response, true); var indexState = response.Indices.Single(); return indexState.Value; })); }
public IProperty GetPropertyMetaData <TIndex>(IndexContext <TIndex> indexContext, string propertyPath) { var properties = this._propertiesMapping.GetOrAdd(indexContext.IndexName, k => { var indexState = this.GetIndexState(indexContext); var propertiesMapped = indexState .Mappings.SelectMany(x => x.Value.Properties); var projection = this.ProjectProperties(typeof(TIndex).Name, propertiesMapped); return(projection); }); return(properties.FirstOrDefault(x => x.Key.Equals(propertyPath, StringComparison.OrdinalIgnoreCase)).Value); }
public void DispatchToKafkaServerTest() { //ARRANGE var documentId = Guid.NewGuid(); var document = new ParentTestClass { Email = "*****@*****.**", IntField = 10, DateFiled = DateTimeOffset.Now, Child = new ChildClass { Name = "Child1", ChildEmail = "*****@*****.**", ChildIntField = 100, ChildDateFiled = DateTimeOffset.Now } }; document.Child.Parent = document; var dependencyResolver = new DependencyResolverMock(); //var client = SearchClientFactory.GetClient(); //var clientFactory = SearchClientFactory.GetClientFactory(); //SearchClientFactory.RegisterDependencies(dependencyResolver); ////create an unique index var indexId = Guid.NewGuid(); var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, indexId); var indexContext = new IndexContext(typeof(ParentTestClass), indexName); var producerConfigManager = new ProducerConfigManager(dependencyResolver); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new ClientIdProvider(), Lifetime.Transient); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new EndPoindProvider(), Lifetime.Transient); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new ProducerTopicConfigProvider(), Lifetime.Transient); ////set up document CRUD controller and create a mock document //var responseHandler = new ResponseHandler(); //var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); //var documentDispatcher = new DocumentDispatcher(clientFactory, indexManager, responseHandler); //var documentclient = new DocumentController(documentDispatcher, indexManager, responseHandler); try { var context = new UpsertDocumentContext <ParentTestClass>(documentId) { Document = document, IndexContext = indexContext }; var dispatcher = new KafkaDispatcherConfuence(producerConfigManager); //ACT dispatcher.UpsertDocument(context); //.Wait(); //ASSERT } finally { } }
public void GetIndexState() { //ARRANGE //var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}", typeof(EsPersonSearch).Name).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext <ParentTestClass>(indexName); var index = new IndexName { Name = indexName, Type = typeof(ParentTestClass) }; var indexDescriptor = new CreateIndexDescriptor(index).Mappings(map => map.Map <EsPersonSearch>(m => m.AutoMap())); //ACT try { var template = client.GetIndexTemplate(d => d.Name("personsearch")); //var documents = client.Search<EsPersonSearch>(s => //s.Query(q => q.MatchAll()) //.Index(index)); // var document = client.Search<EsPersonSearch>(s => //s.Query(q => q.Match(m => // m.Field(f => f.PersonName.LastName) //.Query("Doe"))) //.Index(index)); //var allIndices = client.GetIndex(Indices.All); var indexState = indexManager.GetIndexState(indexContext); var providedName = indexState.Settings["index.provided_name"]; var propertiesMapped = indexState.Mappings.SelectMany(x => x.Value.Properties); //ASSERT Assert.AreEqual(indexName, providedName); } finally { //client.DeleteIndex(index); } }
public void GetPropertyMetaData_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); dependencyResolver.RegisterFactory <QueryClauseBuilder <FieldContext> >(t => new TermClauseBuilder(), Lifetime.Transient); dependencyResolver.RegisterFactory <QueryClauseBuilder <NestedFieldContext> >(t => new NestedClauseBuilder(), Lifetime.Transient); //create an unique index var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext <ParentTestClass>(indexName); var index = new IndexName { Name = indexName, Type = typeof(ParentTestClass) }; var indexDescriptor = new CreateIndexDescriptor(index) .Mappings(map => map.Map <ParentTestClass>(m => m.Properties(p => p.Keyword(d => d.Name(n => n.Email))).AutoMap())); //ACT try { client.CreateIndex(indexDescriptor); Thread.Sleep(1000); //var indexState = client.GetIndex(index); var emailPropertyMetaData = indexManager.GetPropertyMetaData <ParentTestClass>(indexContext, x => x.Email); var childPropertyMetaData = indexManager.GetPropertyMetaData <ParentTestClass>(indexContext, x => x.Child); //ASSERT Assert.AreEqual("keyword", emailPropertyMetaData.Type.Name); } finally { client.DeleteIndex(index); } }
public void GetIndexState_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext <ParentTestClass>(indexName); var index = new IndexName { Name = indexName, Type = typeof(ParentTestClass) }; var indexDescriptor = new CreateIndexDescriptor(index) .Mappings(map => map.Map <ParentTestClass>(m => m.Properties(p => p.Keyword(d => d.Name(n => n.Email))).AutoMap())); //var index = indexManager.BuildIndexName(indexContext); //ACT try { client.CreateIndex(indexDescriptor); //indexManager.BuildIndex(index).Wait(); Thread.Sleep(1000); var indexState = indexManager.GetIndexState(indexContext); var providedName = indexState.Settings["index.provided_name"]; var propertiesMapped = indexState.Mappings.SelectMany(x => x.Value.Properties); //ASSERT Assert.AreEqual(indexName, providedName); } finally { client.DeleteIndex(index); } }
public void GetNestedPropertyMetaData_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext <ParentTestClass>(indexName); var index = new IndexName { Name = indexName, Type = typeof(ParentTestClass) }; var indexDescriptor = new CreateIndexDescriptor(index) .Mappings(map => map.Map <ParentTestClass>(m => m.Properties(p => p.Keyword(d => d.Name(n => n.Email))).AutoMap())); //ACT try { client.CreateIndex(indexDescriptor); Thread.Sleep(1000); //var childPropertyMetaData = indexManager.GetPropertyMetaData<ParentTestClass>(indexContext, x => x.Child.Name); var childPropertyMetaData = indexManager.GetPropertyMetaData <ParentTestClass>(indexContext, "ParentTestClass.Child.Name"); //ASSERT Assert.AreEqual("text", childPropertyMetaData.Type.Name); } finally { client.DeleteIndex(index); //client.DeleteIndex(Indices.All); } }
public void BuildIndexName_name_no_name_provided_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var clientFactory = SearchClientFactory.GetClientFactory(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext(typeof(ParentTestClass)); //ACT var index = indexManager.BuildIndexName(indexContext); //ASSERT Assert.AreEqual(typeof(ParentTestClass).Name.ToLower(), index.Name); Assert.AreEqual(typeof(ParentTestClass), index.Type); }
public void DeletIndex_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext(typeof(ParentTestClass), indexName); var index = indexManager.BuildIndexName(indexContext); //ACT try { client.CreateIndex(index); Thread.Sleep(1000); var indexReqiest = new GetIndexRequest(index); var indexResponse = client.GetIndex(indexReqiest); //delete the index indexManager.DeleteIndex(indexContext); var indexResponseAfterDelete = client.GetIndex(indexReqiest); //ASSERT Assert.IsTrue(indexResponse.IsValid); Assert.IsFalse(indexResponseAfterDelete.IsValid); } finally { client.DeleteIndex(index); } }
public void CreateIndex_if_exist_test() { //ARRANGE var id = Guid.NewGuid(); var dependencyResolver = new DependencyResolverMock(); var client = SearchClientFactory.GetClient(); var clientFactory = SearchClientFactory.GetClientFactory(); //create an unique index var indexName = String.Format("{0}_{1}", typeof(ParentTestClass).Name, id).ToLower(); var responseHandler = new ResponseHandler(); var indexManager = new IndexManager(dependencyResolver, clientFactory, responseHandler); var indexContext = new IndexContext(typeof(ParentTestClass), indexName); var index = indexManager.BuildIndexName(indexContext); //ACT try { indexManager.BuildIndex(index).Wait(); Thread.Sleep(1000); indexManager.BuildIndex(index).Wait(); var indexReqiest = new GetIndexRequest(index); var indexResponse = client.GetIndex(indexReqiest); var indices = indexResponse.Indices.ToList(); var first = indices.First(); var providedName = first.Value.Settings["index.provided_name"]; //ASSERT Assert.IsTrue(indexResponse.IsValid); Assert.AreEqual(1, indices.Count); Assert.AreEqual(indexName, providedName); } finally { client.DeleteIndex(index); } }
public void DispatchToKafkaServerTest1() { //ARRANGE var documentId = Guid.NewGuid(); var document = PersonAggregateFactory.BuildPersonSearchModel(documentId, "Daniel1", "Georgiev1"); var dependencyResolver = new DependencyResolverMock(); ////create an unique index var indexId = Guid.NewGuid(); var indexName = String.Format("{0}_{1}", typeof(EsPersonSearch).Name, indexId); var indexContext = new IndexContext(typeof(EsPersonSearch), indexName); var producerConfigManager = new ProducerConfigManager(dependencyResolver); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new ClientIdProvider(), Lifetime.Transient); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new EndPoindProvider(), Lifetime.Transient); dependencyResolver.RegisterFactory <IConfigurationProvider>((t) => new ProducerTopicConfigProvider(), Lifetime.Transient); try { var context = new UpsertDocumentContext <EsPersonSearch>(documentId) { Document = document, IndexContext = indexContext }; var dispatcher = new KafkaDispatcherConfuence(producerConfigManager); var documentController = new DocumentControllerMock(dispatcher); //ACT documentController.UpsertDocument(context); //.Wait(); //ASSERT } finally { } }
public ProductQueryRepository(IndexContext context) { this.context = context; }
public IndexDao(IndexContext context) { this.context = context; }
public ServicesController(IndexContext db) { _db = db; }
public HomeController(IndexContext db) { _db = db; }
private List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > CreateExpectedResult(IndexContext context, string term, Sort groupSort, int topN) { List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > result = new List <AbstractDistinctValuesCollector.IGroupCount <IComparable> >(); IDictionary <string, ISet <string> > groupCounts = context.searchTermToGroupCounts[term]; int i = 0; foreach (string group in groupCounts.Keys) { if (topN <= i++) { break; } ISet <BytesRef> uniqueValues = new HashSet <BytesRef>(); foreach (string val in groupCounts[group]) { uniqueValues.Add(val != null ? new BytesRef(val) : null); } var gc = new GroupCount(group != null ? new BytesRef(group) : (BytesRef)null, uniqueValues); result.Add(gc); } return(result); }
public virtual void TestRandom() { Random random = Random; int numberOfRuns = TestUtil.NextInt32(random, 3, 6); for (int indexIter = 0; indexIter < numberOfRuns; indexIter++) { IndexContext context = CreateIndexContext(); for (int searchIter = 0; searchIter < 100; searchIter++) { IndexSearcher searcher = NewSearcher(context.indexReader); bool useDv = context.dvType != DocValuesType.NONE && random.nextBoolean(); DocValuesType dvType = useDv ? context.dvType : DocValuesType.NONE; string term = context.contentStrings[random.nextInt(context.contentStrings.Length)]; Sort groupSort = new Sort(new SortField("id", SortFieldType.STRING)); int topN = 1 + random.nextInt(10); List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > expectedResult = CreateExpectedResult(context, term, groupSort, topN); IAbstractFirstPassGroupingCollector <IComparable> firstCollector = CreateRandomFirstPassCollector(dvType, groupSort, groupField, topN); searcher.Search(new TermQuery(new Term("content", term)), firstCollector); IAbstractDistinctValuesCollector <AbstractDistinctValuesCollector.IGroupCount <IComparable> > distinctValuesCollector = CreateDistinctCountCollector(firstCollector, groupField, countField, dvType); searcher.Search(new TermQuery(new Term("content", term)), distinctValuesCollector); // LUCENENET TODO: Try to work out how to do this without an O(n) operation List <AbstractDistinctValuesCollector.IGroupCount <IComparable> > actualResult = new List <AbstractDistinctValuesCollector.IGroupCount <IComparable> >(distinctValuesCollector.Groups); if (VERBOSE) { Console.WriteLine("Index iter=" + indexIter); Console.WriteLine("Search iter=" + searchIter); Console.WriteLine("1st pass collector class name=" + firstCollector.GetType().Name); Console.WriteLine("2nd pass collector class name=" + distinctValuesCollector.GetType().Name); Console.WriteLine("Search term=" + term); Console.WriteLine("DVType=" + dvType); Console.WriteLine("1st pass groups=" + firstCollector.GetTopGroups(0, false).toString()); Console.WriteLine("Expected:"); PrintGroups(expectedResult); Console.WriteLine("Actual:"); PrintGroups(actualResult); Console.Out.Flush(); } assertEquals(expectedResult.Count, actualResult.Count); for (int i = 0; i < expectedResult.size(); i++) { AbstractDistinctValuesCollector.IGroupCount <IComparable> expected = expectedResult[i]; AbstractDistinctValuesCollector.IGroupCount <IComparable> actual = actualResult[i]; AssertValues(expected.GroupValue, actual.GroupValue); assertEquals(expected.UniqueValues.Count(), actual.UniqueValues.Count()); List <IComparable> expectedUniqueValues = new List <IComparable>(expected.UniqueValues); expectedUniqueValues.Sort(nullComparer); List <IComparable> actualUniqueValues = new List <IComparable>(actual.UniqueValues); actualUniqueValues.Sort(nullComparer); for (int j = 0; j < expectedUniqueValues.size(); j++) { AssertValues(expectedUniqueValues[j], actualUniqueValues[j]); } } } context.indexReader.Dispose(); context.directory.Dispose(); } }
private GroupedFacetResult CreateExpectedFacetResult(string searchTerm, IndexContext context, int offset, int limit, int minCount, bool orderByCount, string facetPrefix) { JCG.Dictionary <string, ISet <string> > facetGroups; if (!context.searchTermToFacetGroups.TryGetValue(searchTerm, out facetGroups)) { facetGroups = new JCG.Dictionary <string, ISet <string> >(); } int totalCount = 0; int totalMissCount = 0; ISet <string> facetValues; if (facetPrefix != null) { facetValues = new JCG.HashSet <string>(); foreach (string facetValue in context.facetValues) { if (facetValue != null && facetValue.StartsWith(facetPrefix, StringComparison.Ordinal)) { facetValues.add(facetValue); } } } else { facetValues = context.facetValues; } List <TermGroupFacetCollector.FacetEntry> entries = new List <TermGroupFacetCollector.FacetEntry>(facetGroups.size()); // also includes facets with count 0 foreach (string facetValue in facetValues) { if (facetValue == null) { continue; } int count = facetGroups.TryGetValue(facetValue, out ISet <string> groups) && groups != null?groups.size() : 0; if (count >= minCount) { entries.Add(new TermGroupFacetCollector.FacetEntry(new BytesRef(facetValue), count)); } totalCount += count; } // Only include null count when no facet prefix is specified if (facetPrefix == null) { if (facetGroups.TryGetValue(null, out ISet <string> groups) && groups != null) { totalMissCount = groups.size(); } } entries.Sort(Comparer <TermGroupFacetCollector.FacetEntry> .Create((a, b) => { if (orderByCount) { int cmp = b.Count - a.Count; if (cmp != 0) { return(cmp); } } return(a.Value.CompareTo(b.Value)); })); int endOffset = offset + limit; IList <TermGroupFacetCollector.FacetEntry> entriesResult; if (offset >= entries.size()) { entriesResult = Collections.EmptyList <TermGroupFacetCollector.FacetEntry>(); } else if (endOffset >= entries.size()) { entriesResult = entries.GetRange(offset, entries.size() - offset); } else { entriesResult = entries.GetRange(offset, endOffset - offset); } return(new GroupedFacetResult(totalCount, totalMissCount, entriesResult)); }
public void TestRandom() { Random random = Random; int numberOfRuns = TestUtil.NextInt32(random, 3, 6); for (int indexIter = 0; indexIter < numberOfRuns; indexIter++) { bool multipleFacetsPerDocument = random.nextBoolean(); IndexContext context = CreateIndexContext(multipleFacetsPerDocument); IndexSearcher searcher = NewSearcher(context.indexReader); if (Verbose) { Console.WriteLine("TEST: searcher=" + searcher); } for (int searchIter = 0; searchIter < 100; searchIter++) { if (Verbose) { Console.WriteLine("TEST: searchIter=" + searchIter); } bool useDv = !multipleFacetsPerDocument && context.useDV && random.nextBoolean(); string searchTerm = context.contentStrings[random.nextInt(context.contentStrings.Length)]; int limit = random.nextInt(context.facetValues.size()); int offset = random.nextInt(context.facetValues.size() - limit); int size = offset + limit; int minCount = random.nextBoolean() ? 0 : random.nextInt(1 + context.facetWithMostGroups / 10); bool orderByCount = random.nextBoolean(); string randomStr = GetFromSet(context.facetValues, random.nextInt(context.facetValues.size())); string facetPrefix; if (randomStr == null) { facetPrefix = null; } else { int codePointLen = randomStr.CodePointCount(0, randomStr.Length); int randomLen = random.nextInt(codePointLen); if (codePointLen == randomLen - 1) { facetPrefix = null; } else { int end = randomStr.OffsetByCodePoints(0, randomLen); facetPrefix = random.nextBoolean() ? null : randomStr.Substring(end); } } GroupedFacetResult expectedFacetResult = CreateExpectedFacetResult(searchTerm, context, offset, limit, minCount, orderByCount, facetPrefix); AbstractGroupFacetCollector groupFacetCollector = CreateRandomCollector(useDv ? "group_dv" : "group", useDv ? "facet_dv" : "facet", facetPrefix, multipleFacetsPerDocument); searcher.Search(new TermQuery(new Term("content", searchTerm)), groupFacetCollector); TermGroupFacetCollector.GroupedFacetResult actualFacetResult = groupFacetCollector.MergeSegmentResults(size, minCount, orderByCount); IList <TermGroupFacetCollector.FacetEntry> expectedFacetEntries = expectedFacetResult.GetFacetEntries(); IList <TermGroupFacetCollector.FacetEntry> actualFacetEntries = actualFacetResult.GetFacetEntries(offset, limit); if (Verbose) { Console.WriteLine("Use DV: " + useDv); Console.WriteLine("Collector: " + groupFacetCollector.GetType().Name); Console.WriteLine("Num group: " + context.numGroups); Console.WriteLine("Num doc: " + context.numDocs); Console.WriteLine("Index iter: " + indexIter); Console.WriteLine("multipleFacetsPerDocument: " + multipleFacetsPerDocument); Console.WriteLine("Search iter: " + searchIter); Console.WriteLine("Search term: " + searchTerm); Console.WriteLine("Min count: " + minCount); Console.WriteLine("Facet offset: " + offset); Console.WriteLine("Facet limit: " + limit); Console.WriteLine("Facet prefix: " + facetPrefix); Console.WriteLine("Order by count: " + orderByCount); Console.WriteLine("\n=== Expected: \n"); Console.WriteLine("Total count " + expectedFacetResult.TotalCount); Console.WriteLine("Total missing count " + expectedFacetResult.TotalMissingCount); int counter = 0; foreach (TermGroupFacetCollector.FacetEntry expectedFacetEntry in expectedFacetEntries) { Console.WriteLine( string.Format(CultureInfo.InvariantCulture, "{0}. Expected facet value {1} with count {2}", counter++, expectedFacetEntry.Value.Utf8ToString(), expectedFacetEntry.Count ) ); } Console.WriteLine("\n=== Actual: \n"); Console.WriteLine("Total count " + actualFacetResult.TotalCount); Console.WriteLine("Total missing count " + actualFacetResult.TotalMissingCount); counter = 0; foreach (TermGroupFacetCollector.FacetEntry actualFacetEntry in actualFacetEntries) { Console.WriteLine( string.Format(CultureInfo.InvariantCulture, "{0}. Actual facet value {1} with count {2}", counter++, actualFacetEntry.Value.Utf8ToString(), actualFacetEntry.Count ) ); } Console.WriteLine("\n==================================================================================="); } assertEquals(expectedFacetResult.TotalCount, actualFacetResult.TotalCount); assertEquals(expectedFacetResult.TotalMissingCount, actualFacetResult.TotalMissingCount); assertEquals(expectedFacetEntries.size(), actualFacetEntries.size()); for (int i = 0; i < expectedFacetEntries.size(); i++) { TermGroupFacetCollector.FacetEntry expectedFacetEntry = expectedFacetEntries[i]; TermGroupFacetCollector.FacetEntry actualFacetEntry = actualFacetEntries[i]; assertEquals("i=" + i + ": " + expectedFacetEntry.Value.Utf8ToString() + " != " + actualFacetEntry.Value.Utf8ToString(), expectedFacetEntry.Value, actualFacetEntry.Value); assertEquals("i=" + i + ": " + expectedFacetEntry.Count + " != " + actualFacetEntry.Count, expectedFacetEntry.Count, actualFacetEntry.Count); } } context.indexReader.Dispose(); context.dir.Dispose(); } }
//private AccountContext _accounttext; //Profile user; public AuthModel(IndexContext context) { _context = context; }
private PostfixExpressionContext postfixExpression(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; PostfixExpressionContext _localctx = new PostfixExpressionContext(Context, _parentState); PostfixExpressionContext _prevctx = _localctx; int _startState = 14; EnterRecursionRule(_localctx, 14, RULE_postfixExpression, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { { _localctx = new SimpleExpressionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 115; primaryExpression(); } Context.Stop = TokenStream.Lt(-1); State = 140; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,10,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) { if ( _alt==1 ) { if ( ParseListeners!=null ) TriggerExitRuleEvent(); _prevctx = _localctx; { State = 138; switch ( Interpreter.AdaptivePredict(TokenStream,9,Context) ) { case 1: { _localctx = new IndexContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 117; if (!(Precpred(Context, 6))) throw new FailedPredicateException(this, "Precpred(Context, 6)"); State = 118; Match(LeftBracket); State = 119; argumentExpressionList(0); State = 120; Match(RightBracket); } break; case 2: { _localctx = new CallContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 122; if (!(Precpred(Context, 5))) throw new FailedPredicateException(this, "Precpred(Context, 5)"); State = 123; Match(LeftParen); State = 125; _la = TokenStream.La(1); if ((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << LeftParen) | (1L << Plus) | (1L << PlusPlus) | (1L << Minus) | (1L << MinusMinus) | (1L << Star) | (1L << And) | (1L << Not) | (1L << Tilde) | (1L << Identifier) | (1L << Constant) | (1L << StringLiteral))) != 0)) { { State = 124; argumentExpressionList(0); } } State = 127; Match(RightParen); } break; case 3: { _localctx = new MemberAccessContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 128; if (!(Precpred(Context, 4))) throw new FailedPredicateException(this, "Precpred(Context, 4)"); State = 129; Match(Dot); State = 130; Match(Identifier); } break; case 4: { _localctx = new MemberPointerAccessContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 131; if (!(Precpred(Context, 3))) throw new FailedPredicateException(this, "Precpred(Context, 3)"); State = 132; Match(Arrow); State = 133; Match(Identifier); } break; case 5: { _localctx = new PostfixIncrementContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 134; if (!(Precpred(Context, 2))) throw new FailedPredicateException(this, "Precpred(Context, 2)"); State = 135; Match(PlusPlus); } break; case 6: { _localctx = new PostfixDecrementContext(new PostfixExpressionContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_postfixExpression); State = 136; if (!(Precpred(Context, 1))) throw new FailedPredicateException(this, "Precpred(Context, 1)"); State = 137; Match(MinusMinus); } break; } } } State = 142; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,10,Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return _localctx; }
private ExprContext expr(int _p) { ParserRuleContext _parentctx = Context; int _parentState = State; ExprContext _localctx = new ExprContext(Context, _parentState); ExprContext _prevctx = _localctx; int _startState = 4; EnterRecursionRule(_localctx, 4, RULE_expr, _p); int _la; try { int _alt; EnterOuterAlt(_localctx, 1); { State = 129; switch ( Interpreter.AdaptivePredict(TokenStream,12,Context) ) { case 1: { _localctx = new SignContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 35; _la = TokenStream.La(1); if ( !(_la==T__14 || _la==T__15) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 36; expr(35); } break; case 2: { _localctx = new NegationContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 37; Match(T__25); State = 38; expr(29); } break; case 3: { _localctx = new FormulaeContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 39; Match(T__30); State = 40; expr(26); } break; case 4: { _localctx = new FunctionContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 41; Match(T__34); State = 42; Match(T__7); State = 44; _la = TokenStream.La(1); if (_la==T__53 || _la==ID) { { State = 43; formlist(); } } State = 46; Match(T__8); State = 47; expr(23); } break; case 5: { _localctx = new RepeatStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 48; Match(T__42); State = 52; ErrorHandler.Sync(this); _la = TokenStream.La(1); while (_la==NL) { { { State = 49; Match(NL); } } State = 54; ErrorHandler.Sync(this); _la = TokenStream.La(1); } State = 55; expr(17); } break; case 6: { _localctx = new HelpContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 56; Match(T__43); State = 57; expr(16); } break; case 7: { _localctx = new CompoundContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 58; Match(T__35); State = 60; _la = TokenStream.La(1); if (_la==NL) { { State = 59; Match(NL); } } State = 62; exprlist(); State = 63; Match(T__36); } break; case 8: { _localctx = new IfStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 65; Match(T__37); State = 66; Match(T__7); State = 67; expr(0); State = 68; Match(T__8); State = 70; _la = TokenStream.La(1); if (_la==NL) { { State = 69; Match(NL); } } State = 72; expr(0); } break; case 9: { _localctx = new IfElseStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 74; Match(T__37); State = 75; Match(T__7); State = 76; expr(0); State = 77; Match(T__8); State = 79; _la = TokenStream.La(1); if (_la==NL) { { State = 78; Match(NL); } } State = 81; expr(0); State = 83; _la = TokenStream.La(1); if (_la==NL) { { State = 82; Match(NL); } } State = 85; Match(T__38); State = 87; _la = TokenStream.La(1); if (_la==NL) { { State = 86; Match(NL); } } State = 89; expr(0); } break; case 10: { _localctx = new ForEachStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 91; Match(T__39); State = 92; Match(T__7); State = 93; Match(ID); State = 94; Match(T__40); State = 95; expr(0); State = 96; Match(T__8); State = 98; _la = TokenStream.La(1); if (_la==NL) { { State = 97; Match(NL); } } State = 100; expr(0); } break; case 11: { _localctx = new WhileStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 102; Match(T__41); State = 103; Match(T__7); State = 104; expr(0); State = 105; Match(T__8); State = 107; _la = TokenStream.La(1); if (_la==NL) { { State = 106; Match(NL); } } State = 109; expr(0); } break; case 12: { _localctx = new NextStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 111; Match(T__44); } break; case 13: { _localctx = new BreakStatementContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 112; Match(T__45); } break; case 14: { _localctx = new ParenthesizedContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 113; Match(T__7); State = 114; expr(0); State = 115; Match(T__8); } break; case 15: { _localctx = new IdentifierContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 117; Match(ID); } break; case 16: { _localctx = new StringLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 118; Match(STRING); } break; case 17: { _localctx = new HexLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 119; Match(HEX); } break; case 18: { _localctx = new IntLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 120; Match(INT); } break; case 19: { _localctx = new FloatLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 121; Match(FLOAT); } break; case 20: { _localctx = new ComplexLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 122; Match(COMPLEX); } break; case 21: { _localctx = new NullLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 123; Match(T__46); } break; case 22: { _localctx = new NAContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 124; Match(T__47); } break; case 23: { _localctx = new InfLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 125; Match(T__48); } break; case 24: { _localctx = new NanLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 126; Match(T__49); } break; case 25: { _localctx = new TrueLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 127; Match(T__50); } break; case 26: { _localctx = new FalseLiteralContext(_localctx); Context = _localctx; _prevctx = _localctx; State = 128; Match(T__51); } break; } Context.Stop = TokenStream.Lt(-1); State = 185; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,14,Context); while ( _alt!=2 && _alt!=global::Antlr4.Runtime.Atn.ATN.InvalidAltNumber ) { if ( _alt==1 ) { if ( ParseListeners!=null ) TriggerExitRuleEvent(); _prevctx = _localctx; { State = 183; switch ( Interpreter.AdaptivePredict(TokenStream,13,Context) ) { case 1: { _localctx = new NamespaceContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 131; if (!(Precpred(Context, 38))) throw new FailedPredicateException(this, "Precpred(Context, 38)"); State = 132; _la = TokenStream.La(1); if ( !(_la==T__9 || _la==T__10) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 133; expr(39); } break; case 2: { _localctx = new MemberAccessContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 134; if (!(Precpred(Context, 37))) throw new FailedPredicateException(this, "Precpred(Context, 37)"); State = 135; _la = TokenStream.La(1); if ( !(_la==T__11 || _la==T__12) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 136; expr(38); } break; case 3: { _localctx = new PowerContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 137; if (!(Precpred(Context, 36))) throw new FailedPredicateException(this, "Precpred(Context, 36)"); State = 138; Match(T__13); State = 139; expr(37); } break; case 4: { _localctx = new SequenceContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 140; if (!(Precpred(Context, 34))) throw new FailedPredicateException(this, "Precpred(Context, 34)"); State = 141; Match(T__16); State = 142; expr(35); } break; case 5: { _localctx = new UserOpContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 143; if (!(Precpred(Context, 33))) throw new FailedPredicateException(this, "Precpred(Context, 33)"); State = 144; Match(USER_OP); State = 145; expr(34); } break; case 6: { _localctx = new MultiplicationContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 146; if (!(Precpred(Context, 32))) throw new FailedPredicateException(this, "Precpred(Context, 32)"); State = 147; _la = TokenStream.La(1); if ( !(_la==T__17 || _la==T__18) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 148; expr(33); } break; case 7: { _localctx = new AdditionContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 149; if (!(Precpred(Context, 31))) throw new FailedPredicateException(this, "Precpred(Context, 31)"); State = 150; _la = TokenStream.La(1); if ( !(_la==T__14 || _la==T__15) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 151; expr(32); } break; case 8: { _localctx = new ComparisonContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 152; if (!(Precpred(Context, 30))) throw new FailedPredicateException(this, "Precpred(Context, 30)"); State = 153; _la = TokenStream.La(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__19) | (1L << T__20) | (1L << T__21) | (1L << T__22) | (1L << T__23) | (1L << T__24))) != 0)) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 154; expr(31); } break; case 9: { _localctx = new LogicalAndContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 155; if (!(Precpred(Context, 28))) throw new FailedPredicateException(this, "Precpred(Context, 28)"); State = 156; _la = TokenStream.La(1); if ( !(_la==T__26 || _la==T__27) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 157; expr(29); } break; case 10: { _localctx = new LogicalOrContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 158; if (!(Precpred(Context, 27))) throw new FailedPredicateException(this, "Precpred(Context, 27)"); State = 159; _la = TokenStream.La(1); if ( !(_la==T__28 || _la==T__29) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 160; expr(28); } break; case 11: { _localctx = new FormulaeContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 161; if (!(Precpred(Context, 25))) throw new FailedPredicateException(this, "Precpred(Context, 25)"); State = 162; Match(T__30); State = 163; expr(26); } break; case 12: { _localctx = new RightAssignmentContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 164; if (!(Precpred(Context, 24))) throw new FailedPredicateException(this, "Precpred(Context, 24)"); State = 165; _la = TokenStream.La(1); if ( !((((_la) & ~0x3f) == 0 && ((1L << _la) & ((1L << T__31) | (1L << T__32) | (1L << T__33))) != 0)) ) { ErrorHandler.RecoverInline(this); } else { Consume(); } State = 166; expr(25); } break; case 13: { _localctx = new ListAccessContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 167; if (!(Precpred(Context, 41))) throw new FailedPredicateException(this, "Precpred(Context, 41)"); State = 168; Match(T__4); State = 169; sublist(); State = 170; Match(T__5); State = 171; Match(T__5); } break; case 14: { _localctx = new IndexContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 173; if (!(Precpred(Context, 40))) throw new FailedPredicateException(this, "Precpred(Context, 40)"); State = 174; Match(T__6); State = 175; sublist(); State = 176; Match(T__5); } break; case 15: { _localctx = new FunctionCallContext(new ExprContext(_parentctx, _parentState)); PushNewRecursionContext(_localctx, _startState, RULE_expr); State = 178; if (!(Precpred(Context, 39))) throw new FailedPredicateException(this, "Precpred(Context, 39)"); State = 179; Match(T__7); State = 180; sublist(); State = 181; Match(T__8); } break; } } } State = 187; ErrorHandler.Sync(this); _alt = Interpreter.AdaptivePredict(TokenStream,14,Context); } } } catch (RecognitionException re) { _localctx.exception = re; ErrorHandler.ReportError(this, re); ErrorHandler.Recover(this, re); } finally { UnrollRecursionContexts(_parentctx); } return _localctx; }