Python Programming
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me
Go Back   Dev Shed ForumsProgramming LanguagesPython Programming

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
Get inside! Sample the range of functionality easily built with JMSL Library for Time Series Data Analysis, Heat Maps, Portfolio Optimization, Monte Carlo Simulation, Stock Price Charting and more. Download Now!
  #1  
Old November 30th, 2003, 02:04 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
Search Field

If a search field can be made using Python, can you help me out with making one?

I want this one page where you can look at book reviews. I want the search field to allow you to search by title, author, or genre. If your search didn't have a match, I want it to display

Sorry, <the text that was in the search field> could not be found. Then have the search field below so that the user can search for something else.

If there is a match, I want to display all the results.



Example:
|Title| Learning Python

Results:

Learning Python <= (URL to the book reviews page for this book)
by Mark Lutz and David Ascher

Reply With Quote
  #2  
Old November 30th, 2003, 02:28 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Well i can tell you that its definatly possiable , i'm guessin were talking about a web based search engine, but you should check out this great Python powered search engine..

Gonna need some more info though chief.. what form are you storing this data in i.e. MySQL, pickle, flat file etc. What other features are you wanting.. as much info as you can, would really help

Mark.
__________________
programming language development: www.netytan.com Hula


Reply With Quote
  #3  
Old November 30th, 2003, 02:36 PM
oxygenthief oxygenthief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2003
Posts: 35 oxygenthief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: < 1 sec
Reputation Power: 5
What are you searching against? A database, textfile, XML packet, or using a search from another site, such as Amazon.com or BN.com.

Reply With Quote
  #4  
Old November 30th, 2003, 02:40 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
I want to store this data in what ever is most simple and efficient. I have MySQL, but I don't really want to use it. But if we have to, I will.

Well here's how I want it to look:

<drop down box>
(Options: title, author, and genre)

Then have a search field right next to the drop down box.

Then have a submit button right next to the search field.

If you search for "Learning Python", it will return

Learning Python (URL to the reviews for this book)
by Mark Lutz and David Ascher

If you search for "Mark Lutz" or "David Ascher", it will return all books written by him. Such as:

Learning Python (URL to the reviews for this book)
by Mark Lutz and David Ascher

If you search for "Python", which is the genre this book will be in, it will return all books in the Python genre. Giving the title first which is also the URL to the reviews for that title. Below that will be the author(s).

I want it to be in alphabetical/numerical order.

Was that descriptive enough?

============================

EDIT:

oxygenthief: What ever would work.

The book reviews are made by people who visit my web site and the book reviews are at my web site.

Last edited by MasterChief : November 30th, 2003 at 02:42 PM.

Reply With Quote
  #5  
Old November 30th, 2003, 02:59 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Well, obviously this would ber quite easy in SQL, if you dont wana use MySQL then SQLite would be a great choice (small and fast). If not then we're gonna have to this about how were gonna put this data in a flat file or dictionary/list/tuple...

http://pysqlite.sourceforge.net/

You should also know that using a flat file, or pickle will NOT be as fast as using an SQL database but not overly slow , it does make adding to the book list a little harder..

The layout bit will be easy since its just html so i'm gonna leave that up to you! But you might also want to have a 'show all' in that drop down of yours

So which way do you want to take this?

Mark.

Reply With Quote
  #6  
Old November 30th, 2003, 03:05 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
I choose MySQL. I'm just scared of it. Bad experiences. But if you say that it will be easy, I trust you.

Yeah, the layout will be really simple.

Reply With Quote
  #7  
Old November 30th, 2003, 03:21 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ok so first we need to setup our Database , you should read thought his tutorial..

http://www.devshed.com/Server_Side/...ySQL/page1.html

Just of the top of my head but i'd think your gonna need a table with each of these cols.. id, title, author, genere, link

id being the Primary key

Mark.

Reply With Quote
  #8  
Old November 30th, 2003, 04:10 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
I got MySQLdb. I installed it and was able to import it with no problems. I have not used it yet.

I finished making the layout. Here is the code for that:

Code:
<form action="">
<p>
<select>
<option value="title" selected="selected">title</option>
<option value="author">author</option>
<option value="genre">genre</option>
</select>
<input type="text" name="search" size="100" />
<input type="submit" value="Submit" />
</p>
</form>


(I use XHTML 1.0 Strict)

I finished setting up the database. Here is what I did:

mysql> CREATE DATABASE books;
Query OK, 1 row affected (0.13 sec)

mysql> USE books;
Database changed

mysql> CREATE TABLE books
(id varchar(255),
title varchar(255),
author varchar(255),
genre varchar(255),
link varchar(255));

Query OK, 0 rows affected (0.19 sec)

What do we do now?

Reply With Quote
  #9  
Old November 30th, 2003, 04:21 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ok i'm with ya , one thing i have to point out is here - your id should be auto incremented and your primary key..

Just setting up my copy of your database now and i'll give you a sample script that returns the results from the database

Mark.

Reply With Quote
  #10  
Old November 30th, 2003, 04:44 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
How should the "books" table look?

mysql> CREATE TABLE books
(id ?????????????????,
primary key ?????????,
title varchar(255),
author varchar(255),
genre varchar(255),
link varchar(255));

Reply With Quote
  #11  
Old November 30th, 2003, 05:18 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
I set the table up as...

CREATE TABLE books (
id INT(4) NOT NULL AUTO_INCREMENT,
title VARCHAR(255) NOT NULL,
author VARCHAR(255) NOT NULL,
genre VARCHAR(255) NOT NULL,
link VARCHAR(255),
PRIMARY KEY(id)
);

Mark.

Reply With Quote
  #12  
Old November 30th, 2003, 05:22 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
All right. I dropped the table I had and create the exact same table you have.

Reply With Quote
  #13  
Old December 1st, 2003, 06:25 PM
netytan's Avatar
netytan netytan is offline
Hello World :)
Dev Shed Frequenter (2500 - 2999 posts)
 
Join Date: Mar 2003
Location: Hull, UK
Posts: 2,529 netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level)netytan User rank is Second Lieutenant (5000 - 10000 Reputation Level) 
Time spent in forums: 1 Week 2 Days 17 h 19 m 5 sec
Reputation Power: 63
Send a message via ICQ to netytan Send a message via AIM to netytan Send a message via MSN to netytan Send a message via Yahoo to netytan
Ok, i have attached what i have so far (not finished and will need a little tweeking to do what you wanted..)

Note: i havn't had the time to test this; mainly because i've been very busy with other things but not having any sample data to search against doesnt help much .

Also, the SQL query i'm using is also quite strict, so the the string must be matched exactly within a field for it to be returned.. this still doesnt doesn't have any error capture or layout, all things you should be able to add without much trouble!

Mark.

Edit: if the search is too strict for you we can try MySQLs REGEXP
Attached Files
File Type: py books.py (1.4 KB, 209 views)

Last edited by netytan : December 1st, 2003 at 06:28 PM.

Reply With Quote
  #14  
Old December 1st, 2003, 07:25 PM
MasterChief MasterChief is offline
Contributing User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Feb 2003
Location: Virginia
Posts: 491 MasterChief User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 4 h 47 m 47 sec
Reputation Power: 6
Send a message via AIM to MasterChief Send a message via MSN to MasterChief
Thanks a lot! Greatly appreciated!

You made a typo. I corrected it but I wanted to let you know so that you can correct yours if you want.

It was: MySQLdb.conenct

It should be: MySQLdb.connect

So how do I use this Python script on my web site? Where do I put it?

Reply With Quote