New module: Picture date search

Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Mon, 2006-10-23 19:47

Hi all,

Like a lot of people, I am currently working on a mapping/photo album interface for a CMS. In order to find the right pictures on my gallery2 albums when interpolating GPS track timings, I needed a module to do fuzzy searches on picture dates, so I thought I'd share it with you all here.

I did this pretty quick, the code could be much nicer, I admit, but it does the trick and should not open gaping security holes in your gallery, or crash it - at least I hope, please contribute your patches if I'm wrong.

Here's how it works:

- Unpack the "evdate" module in your modules directory
- Install/activate through the admin interface. No configuration options whatsoever.

Now, when you search your albums, you'll get an extra checkbox to search on picture dates. The module will accept the following syntax:

- If your query is not recognized as a proper date (as 'parsed by PHP as a proper date'), or if the query only contains a year/month/day, then the module will attempt to do a string search on the origination date of the pictures. This way, "2006" will return all pictures taken in 2006, "2006-10" all pictures in October, etc.
- If your query is a complete date/time string, then the module will try to locate a picture taken precisely at that date. Not very useful if you ask me.
- Now, if your query is a complete date string, followed by "+/-" and a time span, then all pictures taken within that span around the date will be returned. Example: "2006-10-23 16:03 +/- 2 hours".

Anyway, let me know what you think of all this, refer to it in the documentation wiki if you think it's production-grade, improve it, etc...

Regards,

Ed

AttachmentSize
evdate.tgz2.91 KB
 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Mon, 2006-10-23 23:46

Looks good. And works on my test install (G2.2 svn) It shows the formatting on the template needs some work with   so that the words don't wrap in the wong spaces.

Added to the User_Contributions

I will make a module in the codex as well, but want to see if the name can change? Why the evdate?

Dave

 
Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Tue, 2006-10-24 08:48

Indeed, no problem with the name change, I just use 'ev' for all my custom dev works so that there is no naming collisions when I upgrade.

Here is the same module renamed as "datesearch" (including the formatting changes mentioned above).

Edouard

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Tue, 2006-10-31 13:38

I could not get date search to work in Gallery 2.1.2

I downloaded the datesearch.tgz.
I unzipped it using winrar, this produced a folder called "datesearch" with a single file.
The single file called "datesearch" has no file extension.
I copied the folder named "datesearch" into my modules folder.
I run Gallery 2 and log in as admin.
I click on Site Admin, then Module.
I look down the list and I see no reference to datesearch at all.

What am I doing wrong?

How come datesearch does not show up in my models list?

 
Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Tue, 2006-10-31 13:46

Hi,

datesearch.tgz contains the following:

    0 2006-10-24 10:49 datesearch/
 2239 2006-10-24 10:49 datesearch/module.inc
    0 2006-10-24 10:49 datesearch/classes/
 7025 2006-10-24 10:48 datesearch/classes/DateSearchDo.class

This probably means something went wrong when you opened the archive. On a unix box, you can open the archive with "tar xvzf", on Windows, I know Winzip opens tar gzipped files fine...

Hope this helps,

Ed

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Tue, 2006-10-31 14:19

Well, that must be the problem then.

However, I just pulled down WinZip 10.0 and it can not read the TAR file. [Error Reading Header After Processing 0 entries]

To avoid these kinds of problems for windows users, is there anyway you can post a "plain/regular" ZIP file with datesearch ready to use?

Thanks!

Atom

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Wed, 2006-11-01 02:38

As requested

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Wed, 2006-11-01 14:02

I have the datesearch installed and it does produce results, but I am not sure if they are correct.

I have 1 image in my gallery, uploaded on 10-30-2006. This image resides at the bottom of a 3 sub-item stack on a root album.
When I issues a date search only (unchek all items in the advanced search and then check Search Picture Date) and type in 2006 in the search field, I get 11 results back. This seems odd to me because I only have one picture in my gallery. All 11 results are the same, that single picture.
Also, if I issue a new search with the letter "z", I get the same thing, 11 results. This should not happen. I should get 0 results when I issue date search with the letter "z" (don't you agree?)

Just offering feedback, in my opinion, the date search does not work correctly. It does produce results, but not correct results.

Having said all that, I still need a datesearch and will probably try to fix this one.

What I would like, however, is to have actual date fields in the Advanced search that are populated by clicking on a calendar icon.

Q: How would I modify the Advanced search template so I can add and pass these additional date value?
Q: What file do I need to change?

Thanks

Atom

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Fri, 2006-11-03 20:20

Still digging around in the code...

Could someone, or Edouard2 post the propper syntax for locating a single file on a single date.

For instance, I have a file that I uploaded on "10/30/2006" (this is what Gallery displays in the search result) and it is the only image uploaded on that date. What do I type in the search field to make that single image come back?

Edouard2 mentions this...
>>If your query is a complete date/time string...
What does a "complete date/time string" look like for Gallery?

Here is the Query that datesearch is generating for items:

SELECT [GalleryItem::id], [GalleryUser::fullName], 
[GalleryUser::userName], [GalleryEntity::modificationTimestamp], 
[GalleryItem::originationTimeStamp] FROM [GalleryItem], 
[GalleryAccessSubscriberMap], [GalleryEntity], [GalleryUser] WHERE 
(ABS( [GalleryItem::originationTimeStamp] - ?) <= 1162587404) AND 
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId] AND 
[GalleryItem::id] = [GalleryEntity::id] AND [GalleryUser::id] = 
[GalleryItem::ownerId] AND 
[GalleryAccessSubscriberMap::accessListId] IN (?,?,?) ORDER BY 
[GalleryEntity::modificationTimestamp] DESC, [GalleryItem::id] DESC 

Here is the quesry that datesearch is generating for count:

SELECT COUNT([GalleryItem::id]) FROM [GalleryItem], 
[GalleryAccessSubscriberMap] WHERE (ABS( 
[GalleryItem::originationTimeStamp] - ?) <= 1162587404) AND 
[GalleryItem::id] = [GalleryAccessSubscriberMap::itemId] AND 
[GalleryAccessSubscriberMap::accessListId] IN (?,?,?) 

As you may notice, my initial passed query of "10/30/2006" is nowhere to be found in the SQL. How does this work?

Shouldn't the where clause have something like...where timdate="10/30/2006"

 
Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Sun, 2006-11-05 16:24

Hi,

I'm afraid my explanations were not very clear in my initial post: The module expects ISO-style date formatting: since US and EU date formatting styles differ (DD/MM/YYYY and MM/DD/YYYY), I chose a 'neutral' formatting, which is also recognized both by PHP and MySQL without the need for extra conversion.

In practice, this means your query should look like this: "YYYY-MM-DD HH:MM:SS". For example, "2006-11-03 15:13:12". For more flexibility, you can also:

- Type in a year only (for example, "2006")
- Type in a year-month (for example, "2006-10")
- Type in a year-month-day (for example, "2006-10-23)
- Type in a full date ("2006-10-23 15:15:00)

You can also add a "+/-" and a time span on your query to search for pictures around a given date: for example "2006-10 +/- 1 month" will give you pictures from september to november. You can use "hours", "minutes", "years", "months" (refer to php.net and how it parses dates for the whole list of options).

Does this help ?

Best regards,

Ed

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Mon, 2006-11-06 14:25

It does help Ed, however, it still does not work on my Gallery 2.

For instance, I have one image in my gallery uploaded on 11/30/2006. Using the date style you have above, I put "2006-10-30 15:13:12" in my search field. I should get nothing because I do not have an image on that exact date or time. Instead, I get all images returned.

A better example is "2006-09-30". I did not even have Gallery installed in September, but I still get all images returned as my result.

Q: You mention that you thought the datesearch was working, so you posted it for all. Have you tried it lately? I'm am wondering if I am doing something wrong, but I also wonder if the datesearch simply does not work?

Q:Has anyone else tried datesearch? Does it work for anyone?

 
Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Mon, 2006-11-06 21:11

Hi Atom,

I just tried, everything works fine on my albums... I also installed the module within a CMS, and for each new article it automatically finds all pictures taken at the date of the article, with no particular issue.

Try to look up the exact date of one particular picture in your albums, and let us know what this date looks like (through the picture properties): there might be localization issues ?

Ed

 
floridave
floridave's picture

Joined: 2003-12-22
Posts: 27300
Posted: Tue, 2006-11-07 04:27
Atom wrote:
This seems odd to me because I only have one picture in my gallery. All 11 results are the same, that single picture.

I have 2 items and see 3 results. The issue is that the results are the album that they are in. This might be the issue.
http://langleycom.com/gallery2/main.php

Dave

____________________________________________________
Blog with G2 || Gallery Frames / Mods || G1 Test Gallery

 
Edouard2

Joined: 2004-08-05
Posts: 6
Posted: Tue, 2006-11-07 09:17

Indeed, the module will also return albums created at the date you're searching, so if you create an album on the 1st of november, and add pictures that were taken on the 1st of November and search for "2006-11-01", then you'll get all those pictures + the thumbnail of the album itself. I just tried your link, Dave, it seems to work fine ?

 
Atom
Atom's picture

Joined: 2006-10-24
Posts: 54
Posted: Tue, 2006-11-07 14:36

I tried your link, floridave and it does work on your site. (I assume you are using the posted code and not some modified version).

But you only have one album. Try adding multiple albums and upload a picture on the same day that you create the album.

Is there any way to modify the SQL so that the search only returns pictures and not albums?

I have never seen SQL like what this datesearch generates. Is the SQL getting parsed somwhere else in the program and turned into "standard" SQL?
For instance, what does this mean: GalleryUser::userName (is this a table name?)

 
jackfr

Joined: 2006-10-19
Posts: 3
Posted: Tue, 2006-11-14 08:56

Hi Guys, I am new to Gallery2 and am developing a site to deal with large amounts of pictures. I need users to search on the time picture was taken. Can this be done with a dropdown list box with your code rather than a text search field?