Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 167829
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T12:20:42+00:00 2026-05-11T12:20:42+00:00

Lets say I have a FirstName > MiddleName > LastName hierarchy (~10k rows, for

  • 0

Lets say I have a FirstName > MiddleName > LastName hierarchy (~10k rows, for sake of the question). This means you could have ‘John > Mary-Anne > Eddy’ or ‘Eddy > John > Jacob’ row. The point being that the hierarchy makes little sense and is very foreign to the user (unlike, say, a Country > State > City structure).

Because its so unstructured and confused, I want to provide the user with an auto complete input box. As they type, it should search for possible substring matches, and when they ‘root’ their search string at a level, it will then restrict the results to below that level.

Now, because there are lots of people named ‘John’, it makes little sense that if they type ‘John’ they only get back results like

  • John > Allen > Alexander
  • John > Allen > Burschawitz
  • John > Allen … repeat 100 times …

Because they’ll never see the unique row ‘Jason > John > Smith’.

Instead, they should get back something like (‘*’ is just an arbitrary indicator to the user of ‘hey, lots more rows below this exist’):

  • John > Allen > *
  • Jason > John > Smith
  • Mike > John > *
  • Mary > Elena > Johnason

If they type ‘John > Al’ then the results would be limited to anything under ‘John >’, but should be grouped similarly to above.

I hope the explanation is clear. The requirements are a bit loose. Just reasonable ones so that a person can search through the tree and find what they are after.

Right now, I have some interesting SQL that looks for the search term in the row, figures out its position, does some substring’ing, group bys, and order by’s to get the above results, but its not performing well enough.

I’m trying to solve this problem on a typical LAMP stack (except with Oracle). Its not shared hosting, so I do have full control over the server. The data changes small amounts every few weeks, and the search results can stay stale for a reasonable amount of time (e.g, a cron that updates the search index isn’t out of the question).

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T12:20:42+00:00Added an answer on May 11, 2026 at 12:20 pm

    Argh. Sorry I wasn’t able to describe my problem. Anyways, here’s the solution I came up with.

    Basically, create a second table from the 3-column table that contains all the distinct values for each successive level of the hierarchy, as well as a column to indicate the depth of that row in the hierarchy.

    E.g. From mytable(A, B, C), create search_t(A, B, C, level)

    So, with ‘One > Two > Three’, you create 3 rows (A, B, C, level):

    • ‘One’, null, null, 1
    • ‘One’, ‘Two’, null, 2
    • ‘One’, ‘Two’, ‘Three’, 3

    When searching, you can constrain the level by picking a value for level and providing values for the upper-level columns:

    WHERE A='One' and level > 1 and (B like '%t%' or C like '%t')

    It can be a bit simplified and generic if you create a search_str column and perform the LIKE matching against that instead.

    WHERE A='One' and level > 1 and search_str like '%t%'

    In retrospect, this would probably have been more apparent if the data were already in an adjacency-list model.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Lets say I have this class class Child { public string FirstName { get;
Lets say we have some basic AR model. class User < ActiveRecord::Base attr_accessible :firstname,
Lets say you have an XML like like this: <data> <messages> <message name=Person id=P>
In SQL Server 2008, let's say I have an index (LastName, FirstName) on the
Lets say I have the following XML file: <?xml version=1.0 encoding=utf-8?> <Customers xmlns:xsi=http://www.w3.org/2001/XMLSchema-instance xsi:noNamespaceSchemaLocation=Customer.xsd>
lets say i have a custom widget which has a ClickHandler. Here's the example:
Imagine you have a map like this: (def person { :name { :first-name John
Lets say I have the following entities that map to database tables (every matching
Let's say I have a database filled with people with the following data elements:
Let's say I have the following model: Person <AR def name [self.first_name,self.middle_name,self.last_name].select{|n| n.present?}.join(' ')

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.