|
|
|||||||||
|
|||||||||
| |||||||||
|
|
|
| |||||||||
![]() |
|
|
«
Previous Thread
|
Next Thread
»
|
Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
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
|
|||
|
|||
|
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 |
|
#2
|
||||
|
||||
|
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. |
|
#3
|
|||
|
|||
|
What are you searching against? A database, textfile, XML packet, or using a search from another site, such as Amazon.com or BN.com.
|
|
#4
|
|||
|
|||
|
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. |
|
#5
|
||||
|
||||
|
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. |
|
#6
|
|||
|
|||
|
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. |
|
#7
|
||||
|
||||
|
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. |
|
#8
|
|||
|
|||
|
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? |
|
#9
|
||||
|
||||
|
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. |
|
#10
|
|||
|
|||
|
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)); |
|
#11
|
||||
|
||||
|
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. |
|
#12
|
|||
|
|||
|
All right. I dropped the table I had and create the exact same table you have.
|
|
#13
|
||||
|
||||
|
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 Last edited by netytan : December 1st, 2003 at 06:28 PM. |
|
#14
|
|||
|
|||
|
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? |