Page 1 of 1

Search multiple keywords from text file database

Posted: Tue Nov 03, 2009 5:54 am
by psaha
Search multiple keywords from text file database

I have a text file database:
webdatabase.txt
------------------------------------------------------------------------------
1257143509||google web search||Enables users to search the Web, Usenet, and images||www.google.com->
1245876563||yahoo portal||free Yahoo! Mail & Instant messenger, news, finance||www.yahoo.com->
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com
------------------------------------------------------------------------------

The above text file database has column separator ||, and row separator as ->
The first column, generated from time() function, can be used as primary key.

I want to search several keyword(S) and the program will open
webdatabase.txt to search the keyword(S) from column1 and column2. Column0 and column3 need not to search.
Display the rows in DESC order. More occurrence to less occurrence.

Example: If anyone enter: web money
output will be:
1257143509||google web search||Enables users to search the Web, Usenet, and images||www.google.com
then
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com

(Without column separator)

Example 2: If anyone enter: Instant messenger portal
Display: 1245876563||yahoo portal||free Yahoo! Mail & Instant messenger, news, finance||www.yahoo.com
1254555967||MSN Live||Microsoft's portal, offering MSNBC News, search, sports, MSN Money||www.msn.com


-- Advance Thanks for your help

I have tried lots of code but getting 2 problems 1. Several keywords 2. Display the whole row in pagination format. I am not sending my php code yet as I want to see the different approach and concept.
- Thanks again and waiting for reply.

[Note: I promise, next time I will do in mysql database]

Re: Search multiple keywords from text file database

Posted: Thu Nov 05, 2009 9:54 pm
by psaha
Still no reply!!

Re: Search multiple keywords from text file database

Posted: Fri Nov 06, 2009 10:27 pm
by McInfo
Use SQLite. It's built into PHP. There is no server to install and the database is stored in a single file.

Creating an SQLite database is this easy:

Code: Select all

<?php
$db = sqlite_open('./database.sqlite');
sqlite_query($db, 'CREATE TABLE user (name VARCHAR(30), email VARCHAR(256))');
sqlite_query($db, 'INSERT INTO user (name, email) VALUES ("Tom", "tom@tom.tom")');
sqlite_query($db, 'INSERT INTO user (name, email) VALUES ("Sam", "sam@sam.sam")');
sqlite_close($db);
Retrieving records is this easy:

Code: Select all

<?php
$db = sqlite_open('./database.sqlite');
$result = sqlite_query($db, 'SELECT name, email FROM user');
foreach (sqlite_fetch_all($result) as $row) {
    printf('<p>%s: %s</p>', $row['name'], $row['email']);
}
sqlite_close($db);
Sorting and searching is handled with SQL queries. See SQLite SQL Syntax.

Edit: This post was recovered from search engine cache.

Re: Search multiple keywords from text file database

Posted: Sun Nov 15, 2009 10:49 am
by PM2008
For more comprehensive searches, you can use script http://www.biterscripting.com/helppages ... lStrs.html . It is for searching email files with multiple key words and key phrases, but any non-email files can be searched as well.


Also, take a look at http://www.biterscripting.com/LearningS ... sson5.html . It is a tutorial on how to develop scripts for searching files. Look at the scripts filesearch and emailsearch.

Re: Search multiple keywords from text file database

Posted: Sun Nov 15, 2009 12:12 pm
by McInfo
biterScripting is not PHP.

Edit: This post was recovered from search engine cache.