Hi,

I'd like to offer and discuss a patch that I've written for our site. I'm not sure if you like the idea and/or its implementation, but we will be using it at our site anyway, so I won't be disappointed or angry if you reject it :-) The patch is against 6.x-1.x-dev (2008-Jun-16).

Our research assistants like the filter stuff for e.g. listing their own work or a "last years publication" block. But they also demanded for a "quick search" function for biblio, where they could enter e.g. "knuth 1984 tex" to find everything Donald Knuth wrote about TeX in 1984, no matter if "tex" would appear in a book title, conference name, keywords, abstract etc.

I tried two ways: First was making a biblio filter that would just "rlike" over the concatented fields of a biblio node. Drawbacks were that I had to filter the search input myself and that the mysql expression got a bit complicated in case of several "OR" in the search request. Also it was a bit tricky for me to get all the allowed fields for an input type to search just over them etc.

So I decided for the other way: using the drupal search and presenting the result in the biblio style. This is very easy to reach without writing a lot of code. I just let node_search do all the work, so I don't have to care about stuff like parsing the query etc. However, to be able to sort or export the results without adding a lot of code for a special case, I store the results as a filter which adds "where n.nid in (list of nids)" where the list of node ids is generated from the node_search.

Although search is stored as a filter, I didn't make it combineable with other filters, because I think that filtering and search are two different things that I wouldn't like to combine. Therefore entering a search query resets the filters, and selecting a filter resets the stored search query.

I placed the search box on the main biblio page for quick access. You make it smaller by uncommenting the code lines in the search form to make it collapsible. I added an option on the configuration page to enable or hide the search box. Additionally, it honors the permission setting for the drupal filter tab.

To find any results, the biblio nodes must be indexed. This is usually done by drupals cron job, but I manually enforce indexing of new or updated nodes so that you can search over them right after saving/updating. I found it confusing when I entered a new book and then couldn't find it :-) This indexing option can also be en- or disabled on the configuration page.

A drawback of drupal's search is the lack of a partial word search, see http://drupal.org/node/103548 It's gonna be in drupal 7, but for drupal 6 I find it confusing when I search for "TeX" in our biblio list and don't find books about "LaTeX". That would have worked with the "rlike" filter search over all the biblio fields, which I didn't implement, so I decided to rewrite the two-line patch from http://drupal.org/node/103548 to make partial word search work for drupal 6. I attach this patch, too, so that everyone who wants to use our search box can decide if he want's substring search or not.

I will be glad about any kind of comments, discussions, proposals etc. What I plan next is highlightning the search keywords for the detailed view of a biblio node, which I would prefer over adding a snippet to the search results, as it is done with the normal drupal search.

cu,
Frank

Comments

Anonymous’s picture

StatusFileSize
new11.44 KB

Hmm, although the patches showed up in the preview they weren't transferred to the final post. Trying again...

Anonymous’s picture

Strange, I cannot upload the patch for the partial word search, whatever I try :-) Anyway, I've attached to the thread cited above already, so you can get it from here:
http://drupal.org/files/issues/partial_word_search_6_2.patch

Anonymous’s picture

StatusFileSize
new11.92 KB

Fixed version. The old one resetted e.g. $node->menu['mlid'] when indexing new or updated node. Also changed code to perform nodeapi only for biblio types and not all node types.

Frank Steiner’s picture

StatusFileSize
new12.36 KB

Version 3.
- indexing still failed right after inserting/updating
- changed generation of where clause to avoid injection issue because of unquoted %s

Ron, let me know if you are interested in testing this patch some time (when you find enough time to do so). If yes, I will continue to generate patches from my internal version whenever I fix sth.

cu,
Frank

rjerome’s picture

Thanks Frank,

I'm still in vacation mode for another couple of weeks, but I'll try to look at it then.

Ron.

Frank Steiner’s picture

Thanks! Have a nice time :-)

Frank Steiner’s picture

StatusFileSize
new12.38 KB

Forgot to remove a <p></p> from the code, making it impossible to restyle the form bottom margin with own css files. Changed css accordingly. Fixed input width for search field.

Frank Steiner’s picture

StatusFileSize
new12.68 KB

The search filter should not be combined with other filters. However, I forgot to handle URLs like biblio/aid/1 which will add the author filter without using the filter form. This is fixed by ignoring all parameters to biblio_db_search when the search filter is set.

Frank Steiner’s picture

StatusFileSize
new13.85 KB

Ok, another version. First I had to take back the last change because this would also exclude arguments for sorting results by authors first letter etc. So now the filters are still reset when you enter a search term, but you can use author sorting and even add filters by manually entering a matching URL like year/2007 or aid/1

But the main change is that I enabled the search filter for manually passing to biblio_db_search(). Thus, you can now have a code like

biblio_db_search('search', '"DNA analysis"', 'inline')

to show all papers about DNA analysis. Remember that a space is an "or" in drupal search, so we need the "" here.

And now this can be combined like

biblio_db_search('author', '"Frank Steiner"', 'search', 'DNA', 'inline')

to show all my papers about DNA (zero, acutally :-)).

rjerome’s picture

Status: Needs review » Fixed

committed to CVS

Status: Fixed » Closed (fixed)

Automatically closed -- issue fixed for two weeks with no activity.