Database Searching Algorithms

Hi..

I have to do some research about database searching algorithms.

Would someone here help me and give a list of that algorithms and which one is the best.

What is the name of this algorithms which when u type in a key such "a" then it display a list of information that started with "a".

[315 byte] By [Kuntilanaka] at [2007-10-3 2:53:55]
# 1

If you are custom making a db searcher... good luck :) I don't know how fast it'll be... But It might not be toooooooo bad.

Idea:

1) Setup a java thread pool

2) Have multiple searching criteria

3) search by individual letter using String.startWith(char)

4) search by certain phrase using step 3, String instead of char

5) If sorting is involved, I advise to use the "quick sort"

good?

tumpa at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...
# 2
Yup i'm making a db searcher and your idea sounds good to me, but can u show me some example here...example of String.startWith(char) and how the search works..
Kuntilanaka at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...
# 3

well i don't have time to make my own db searcher... plus, you could just use MySQL and send queries for it to search... but ok.

Some ideas...

string searchWord = "fall";

for ( Object obj : My_list)

{

String text = (String)obj;

if ( text.startsWith( searchWord )

{

list_of_finds.add( text );

}

if ( text.endsWith( searchWord )

{

list_of_finds.add( text );

}

String keyword[] = text.split( searchWord ); //splits the text any time the search word is found

for ( int i = 0; i < keyword.length; i++ )

{

if (keyword[i].equals( searchWord ) == true )

{

list_of_finds.add( text ); //add to a list of the results

}

}

}

ah-haaaaaa at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...
# 4

I guess I have more time than I thought... :)

Here is a full working example all in one class...

import javax.swing.*;

import java.awt.*;

import java.awt.event.*;

public class MAIN

{

DefaultListModel model_my_list = new DefaultListModel();

JList my_list = new JList(model_my_list);

DefaultListModel model_list_of_finds = new DefaultListModel();

JList list_of_finds = new JList(model_list_of_finds);

JTextField search_box = new JTextField(20);

JTextField add_box = new JTextField(20);

public MAIN()

{

JFrame frame = new JFrame( "Search test" );

frame.setSize( 500, 500 );

//

Container container = frame.getContentPane();

GridBagLayout gbl = new GridBagLayout();

container.setLayout(gbl);

GridBagConstraints gbc = new GridBagConstraints();

//

Action actionAdd = new AbstractAction("ADD")

{

public void actionPerformed(ActionEvent evt)

{

model_my_list.add( model_my_list.size(), add_box.getText() );

add_box.setText("");

}

};

JButton buttonAdd = new JButton(actionAdd);

buttonAdd.setPreferredSize( new Dimension( 100, 30 ) );

gbc.gridx = 2;

gbc.gridy = 2;

gbl.setConstraints(buttonAdd, gbc);

container.add( buttonAdd );

Action actionSearch = new AbstractAction("SEARCH")

{

public void actionPerformed(ActionEvent evt)

{

search( search_box.getText() );

}

};

JButton buttonSearch = new JButton(actionSearch);

buttonSearch.setPreferredSize( new Dimension( 100, 30 ) );

gbc.gridx = 2;

gbc.gridy = 4;

gbl.setConstraints(buttonSearch, gbc);

container.add( buttonSearch );

//

JLabel add_label = new JLabel( "Add element" );

gbc.gridx = 1;

gbc.gridy = 1;

gbl.setConstraints(add_label, gbc);

container.add( add_label );

gbc.gridx = 1;

gbc.gridy = 2;

gbl.setConstraints(add_box, gbc);

container.add( add_box );

JLabel search_label = new JLabel( "Search keyword" );

gbc.gridx = 1;

gbc.gridy = 3;

gbl.setConstraints(search_label, gbc);

container.add( search_label );

gbc.gridx = 1;

gbc.gridy = 4;

gbl.setConstraints(search_box, gbc);

container.add( search_box );

//

JLabel all_label = new JLabel( "All elements" );

gbc.gridx = 1;

gbc.gridy = 5;

gbl.setConstraints(all_label, gbc);

container.add( all_label );

JScrollPane all_scroll = new JScrollPane( my_list );

gbc.gridx = 1;

gbc.gridy = 6;

gbl.setConstraints(all_scroll, gbc);

container.add( all_scroll );

//

JLabel found_label = new JLabel( "Searched elements" );

gbc.gridx = 2;

gbc.gridy = 5;

gbl.setConstraints(found_label, gbc);

container.add( found_label );

JScrollPane found_scroll = new JScrollPane( list_of_finds );

gbc.gridx = 2;

gbc.gridy = 6;

gbl.setConstraints(found_scroll, gbc);

container.add( found_scroll );

//

frame.pack();

frame.setResizable( false );

frame.setVisible( true );

}

public void search( String searchWord )

{

model_list_of_finds.clear(); //empty

for ( int i = 0; i < model_my_list.size(); i++ )

{

String text = (String)model_my_list.get(i);

if ( text.startsWith( searchWord ) )

{

model_list_of_finds.add( model_list_of_finds.size(), text );

continue;

}

if ( text.endsWith( searchWord ) )

{

model_list_of_finds.add( model_list_of_finds.size(), text );

continue;

}

String keyword[] = text.split( searchWord );

if (keyword.length > 1 ) //if there was a split... there was a find

{

model_list_of_finds.add( model_list_of_finds.size(), text );

continue;

}

}

}

public static void main ( String args[] )

{

new MAIN();

}

}

ah-haaaaaa at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...
# 5
Hi ah-haaaa thanx for your time and the coding, i really appreciate that...u said that it can be done with MySQL query and i think it's a good idea too...how was it?if u do not have much time just show me the snippet code only...
Kuntilanaka at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...
# 6
Go to...javaalmanac.comSearch anything about java... it'll tell you what to do...Also look at the forums of the JDBC to find out about java's connectivity abilities...good luck
pointOfa at 2007-7-14 20:42:59 > top of Java-index,Other Topics,Algorithms...