Go to main content

Textpattern CMS support forum

You are not logged in. Register | Login | Help

#1 2008-11-28 00:22:10

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Front end file search (!)

Hi,

I’ve got a client that wants a document “database” filled with PDF’s and perhaps other kinds of files. The problem is that the client also want the files to be searchable through filename, created date, category and description. Which meens a text search field for at least the filename and description parts of the file MySQL database. (basicly exactly the same search function that exists in Textpattern admin in the “files” tab.)

Ive searched for plugins and none exist for searching files (or anything else then articles for that matter). Ive googled like a mad man and found zero.

Ive searched this forum and all posts about file searching is more then a year old. The ones that gave me some info on how to progress didnt get me all the way though…

From what Ive figured out the built in search function is built in to the “article part” and “search.php” is’nt used any more. Also there is some info on how to continue looking at how the <txp:file_download_list /> tag works in “taghandlers.php”. (Ive even looked into rebuilding the ob1_advanced_search)

I need help and support on how to get such a function going. Im quite experienced in php, Im just on a tight schedule here and cant get all the parts together on how the Textpattern search function is built.

One of my ideas is to use “search.php” for searching “txp_file” and change it to look for words in “filename” and “description” instead of “title” and “body”. Dumb?

Is there anyone that know the Textpattern source inside out and got bright ideas on how to approach this issue?

Offline

#2 2008-11-28 00:38:48

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Front end file search (!)

If you want to real search you need to build index for those column inside txp_file-table – or you can use rlike “cheatsheet”.

In example something like (don’t use it directly because I don’t even remember field names out of fly – wrote on fly):

$q = doSlash(gps('q'));
$rs = safe_rows_start("ID",'txp_file',"(description rlike '$q' or filename rlike '$q') and Posted < now());

With that you get IDs you want to extract. Now you can either feed them directly to file_download_list() or you can assocate IDs data automatically, like file_download_list does assocate the tag data.

Easy. I build some time ago same kind of plugins for different purposes. Everyone took about 5 minutes to code and implement to template :D

Offline

#3 2008-11-28 00:55:11

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

Wow, your fast Gocom (at answering also)! Why havnt you made the plugins available to the masses? =)
Thanks alot

But, ah ok, yeah the index. But “feed them directly to file_download_list() or you can assocate IDs data automatically” – what and/or how do you meen that practicaly? (I get it that you meen the file_download_list() function but Im not sure I know exactly how it works, yet)

Do you meen changing the function so that you open up more options for the tag?

Offline

#4 2008-11-28 01:06:24

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Front end file search (!)

Agogo wrote:

Why havnt you made the plugins available to the masses? =)

One of them I have, other’s are not kinda my property. The one is:

rah_plugin_search

That uses that exact same cheat-way when there isn’t required index/keys in the db :)

In example you can feed the id to file functions with id $atts array element, or you can use those assocate functions that Textpattern contains, and by default to uses populate data.

Btw, I can always be hired to write even more and more plugins :D lol. I’m trying to reach the 1 hundred goal (not much left tho).

Last edited by Gocom (2008-11-28 01:12:41)

Offline

#5 2008-11-28 17:33:07

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

You want to hired eyh? =)
I’ll keep that in mind for later…

Anyhow, I’ve been out on business all day and won’t be working this evening but will try your method as soon as I can tomorrow and get back to ya.
Thanks!

Offline

#6 2008-12-01 00:29:31

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

Hi,

Ive managed to make my own search plugin and make it work in the regular article section of the database but Im having trouble getting results when searching the txp_file table.

The search seems to work in the table but the problem is the output that I send to file_download(). file_download_list() cant be used since it doesnt support the id tag. file_download() however does support it so thats why I use it.

When I assign an id manually ( ‘id’ => ‘26’ ) I do get a result that matches with the number of files Ive got in the database. However, when I try to assign the $id tag to the id I get no result at all…

Any ideas?

PS. I would insert my code here if I knew how! Im a real noob.

Offline

#7 2008-12-01 00:34:22

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

After reading the instructions.. Ehrm.. Here is my code:

	function mms_file_search($atts) {
		extract(lAtts(array(
			'form' => 'search_results'
		),$atts));
		$out = array();
		$q = doSlash(gps('mms'));
		$rs = safe_rows_start("filename",'txp_file',"(filename rlike '$q' or description rlike '$q')");
		while(nextRow($rs)) {
			$out[] = file_download(array(
				'id' => $id
			));
		}
		return implode('',$out);
	}

Last edited by Agogo (2008-12-01 00:43:18)

Offline

#8 2008-12-01 01:05:30

rsilletti
Moderator
From: Spokane WA
Registered: 2004-04-28
Posts: 707

Re: Front end file search (!)

You might consider this using Custom Fields wet_haystack , or perhaps as a starting point for further development.
There is also this ras_file_download_list (it can see the file ids) if that would save you some time.

After looking at your code for a bit – one solution may be to build a comma delimited list of ids that you want returned by ras_file_download_list as a tag, then parse the tag result as an attribute value for “id”, this way if you are using 4.0.7.

<txp:ras_file_download_list id='<txp:your_values />' />

Last edited by rsilletti (2008-12-01 01:23:12)

Offline

#9 2008-12-01 01:14:36

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Front end file search (!)

How could that code work? It is just rip from my rah_plugin_search with out no tail or head :D You should atleast change the atts and leave the extract.

For easier solution, already day old: rah_file_search

Last edited by Gocom (2008-12-01 01:21:59)

Offline

#10 2008-12-01 01:35:01

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

lol, yeah it is a rip from your plugin, sorry should’ve added that. Times a factor…
And. Lets just say Im not experienced in Textpattern plugins.

To be honest I freaked out cause the code should’ve worked at a earlier stage, but didnt (When the only difference between your rah_file_search plugin and my rip version of your rah_plugin_search was this):

if($q) {

I guess I let a type-o slip in somewhere… Thats what you get from working to late.

Thanks alot though!

Offline

#11 2008-12-01 01:42:49

Gocom
Developer Emeritus
From: Helsinki, Finland
Registered: 2006-07-14
Posts: 4,533
Website

Re: Front end file search (!)

Agogo wrote:

I guess I let a type-o slip in somewhere… Thats what you get from working to late.

No, there are plenty mismatches. First is the query (you aren’t even pulling IDs and you are also using all rows, when some of files aren’t live), second is you don’t extract values, and then there are those undefined variables ;D

And that is kinda plain PHP, so, there isn’t any TXP factor in general. And all code is human readable as you just know the language.

Last edited by Gocom (2008-12-01 01:50:02)

Offline

#12 2008-12-01 01:49:40

Agogo
Member
From: Sthlm, Sweden
Registered: 2008-11-27
Posts: 31

Re: Front end file search (!)

Still cant find the errors, but as I wrote, it should have worked at an earlier state – which was this:

	function mms_file_search($atts) {
		extract(lAtts(array(
			'form' => 'file_search'
		),$atts));
		$out = array();
		$q = doSlash(gps('mms'));
		$rs = safe_rows_start("id",'txp_file',"(description rlike '$q' or filename rlike '$q') and status == '4' and category != ''");
		while($a = nextRow($rs)) {
			extract($a);
			$out[] = article_custom(array(
				'id' => $id
			));
		}
		return implode('',$out);
	}

Can you find the errors? (the $q = doSlash(gps('mms')); isnt wrong, Ive changed it)

Offline

Board footer

Powered by FluxBB