hierarchy

Getting hierarchy data from self-referencing tables

爱⌒轻易说出口 提交于 2019-11-28 18:19:55
Let's say you have the following table: items(item_id, item_parent) ... and it is a self-referencing table - item_parent refers to item_id . What SQL query would you use to SELECT all items in the table along with their depth where the depth of an item is the sum of all parents and grand parents of that item. If the following is the content of the table: item_id item_parent ----------- ----------- 1 0 2 0 3 2 4 2 5 3 ... the query should retrieve the following set of objects: {"item_id":1,"depth":0} {"item_id":2,"depth":0} {"item_id":3,"depth":1} {"item_id":4,"depth":1} {"item_id":5,"depth":2}

Elasticsearch - using the path hierarchy tokenizer to access different level of categories

落花浮王杯 提交于 2019-11-28 17:14:20
问题 I'm very new in Elasticsearch and have a question about the hierarchical tokenizer of a path. Here is my code example: My mapping code: PUT /my_index { "settings": { "analysis": { "analyzer": { "path-analyzer": { "type": "custom", "tokenizer": "path-tokenizer" } }, "tokenizer": { "path-tokenizer": { "type": "path_hierarchy", "delimiter": "." } } } }, "mappings": { "my_type": { "dynamic": "strict", "properties": { "group_path": { "type": "string", "index_analyzer": "path-analyzer", "search

Flatten Adjacency List Hierarchy To A List Of All Paths

*爱你&永不变心* 提交于 2019-11-28 16:55:23
I have a Table that stores Hierarchical information using the Adjacency List model. (uses a self referential key - example below. This Table may look familiar ): category_id name parent ----------- -------------------- ----------- 1 ELECTRONICS NULL 2 TELEVISIONS 1 3 TUBE 2 4 LCD 2 5 PLASMA 2 6 PORTABLE ELECTRONICS 1 7 MP3 PLAYERS 6 8 FLASH 7 9 CD PLAYERS 6 10 2 WAY RADIOS 6 What is the best method to "flatten" the above data into something like this? category_id lvl1 lvl2 lvl3 lvl4 ----------- ----------- ----------- ----------- ----------- 1 1 NULL NULL NULL 2 1 2 NULL NULL 6 1 6 NULL NULL 3

SQL Server: How to get all child records given a parent id in a self referencing table

旧巷老猫 提交于 2019-11-28 15:43:42
Hi I have a table which references itself and I need to be able to select the parent and all it's child records from a given parent Id. My table is as follows: ID | ParentID | Name ----------------------- 1 NULL A 2 1 B-1 3 1 B-2 4 2 C-1 5 2 C-2 So for the above example I'd like to be able to pass in a value of 1 and get all the records above. So far, I've come up with the following recursive table-valued-function but it's not behaving as expected (only returning the first record). CREATE FUNCTION [dbo].[SelectBranches] ( @id INT ,@parentId INT ) RETURNS @branchTable TABLE ( ID INT ,ParentID

Getting activity from context in android

醉酒当歌 提交于 2019-11-28 15:11:04
This one has me stumped. I need to call an activity method from within a custom layout class. The problem with this is that I don't know how to access the activity from within the layout. ProfileView public class ProfileView extends LinearLayout { TextView profileTitleTextView; ImageView profileScreenImageButton; boolean isEmpty; ProfileData data; String name; public ProfileView(Context context, AttributeSet attrs, String name, final ProfileData profileData) { super(context, attrs); ...... ...... } //Heres where things get complicated public void onClick(View v) { //Need to get the parent

PHP Create breadcrumb list of every value in nested array

我怕爱的太早我们不能终老 提交于 2019-11-28 14:50:50
I have an array that looks like the following: [ 'applicant' => [ 'user' => [ 'username' => true, 'password' => true, 'data' => [ 'value' => true, 'anotherValue' => true ] ] ] ] What I want to be able to do is convert that array into an array that looks like: [ 'applicant.user.username', 'applicant.user.password', 'applicant.user.data.value', 'applicant.user.data.anotherValue' ] Basically, I need to somehow loop through the nested array and every time a leaf node is reached, save the entire path to that node as a dot separated string. Only keys with true as a value are leaf nodes, every other

How should I deal with object hierarchies in a RESTful API?

丶灬走出姿态 提交于 2019-11-28 14:23:49
问题 I am currently designing the API for an existing PHP application, and to this end am investigating REST as a sensible architectural approach. I believe I have a reasonable grasp of the key concepts, but I'm struggling to find anybody that has tackled object hierarchies and REST. Here's the problem... In the [application] business object hierarchy we have: Users L which have one-to-many Channel objects L which have one-to-many Member objects In the application itself we use a lazy load

Import Error. Circular References

浪子不回头ぞ 提交于 2019-11-28 11:35:52
I have a package like this package/ __init__.py subpackage1/ __init__.py moduleA.py moduleB.py moduleC.py moduleD.py subpackage2/ __init__.py moduleX.py moduleY.py moduleZ.py In moduleB.py, I am importing from moduleA import bar In moduleA, I am importing from moduleB import foo I am getting ImportError. ImportError: cannot import name foo What could be the problem here ? and to avoid this problem, what should I do ? and what should I write in _ init _ .py pf package, subpackage1, subpackage2 ? _ init _ .py of subpackage1 from moduleA import * from moduleB import * from moudleC import * from

Build JSON Hierarchy from Structured Data

匆匆过客 提交于 2019-11-28 11:13:09
C# | .NET 4.5 | Entity Framework 5 I have data coming back from a SQL Query in the form of ID,ParentID,Name. I'd like to take that data and parse it into a Hierarchical JSON string. So far it seems to be much more of a daunting task than it should be. Since I'm using Entity the data comes back nicely to me as an IEnumerable. Now I believe I just need some form of recursion, but I'm not quite sure where to start. Any help is appreciated. Data Returns as id parentId name 1 1 TopLoc 2 1 Loc1 3 1 Loc2 4 2 Loc1A Code is public static string GetJsonLocationHierarchy(long locationID) { using

Rendering a hierarchy using LINQ?

帅比萌擦擦* 提交于 2019-11-28 10:22:44
Let say we have a class Category { ID, Name, ParentID } and a List 1, 'Item 1', 0 2, 'Item 2', 0 3, 'Item 3', 0 4, 'Item 1.1', 1 5, 'Item 3.1', 3 6, 'Item 1.1.1', 4 7, 'Item 2.1', 2 Can we using LINQ to render a tree like: Item 1 Item 1.1 Item 1.1.1 Item 2 Item 2.1 Item 3 Item 3.1 Any help is appreciated! Here's the "LINQ-only" version: Func<int, int, string[]> build = null; build = (p, n) => { return (from x in categories where x.ParentID == p from y in new[] { "".PadLeft(n)+ x.Name }.Union(build(x.ID, n + 1)) select y).ToArray(); }; var lines = build(0, 0); Yes, it's recursive LINQ. Per NVA