words in the middle of the title

bneel - April 25, 2008 - 14:14
Project:Node Quick Find
Version:5.x-1.0
Component:Miscellaneous
Category:feature request
Priority:normal
Assigned:Unassigned
Status:by design
Description

Hi Thanks for your module. It is very simple but very useful.
I was wondering if the autocomplete could work when you are typing words in the middle of the title.

For example :
if you have 3 nodes in your website
DRUPAL IS COOL
DRUPAL IS THE BEST
DRUPAL IS THE FUTURE

IF your search start by DRUPAL, you'll have the 3 nodes' title in the list
But if your search start by COOL, there'll be no title in the list
I tried to use this http://drupal.org/node/208424 to change the module, but without any success.
Maybe you'll find something ?
Thanks for your help and your module.
Benjamin

#1

nicholasThompson - April 30, 2008 - 09:03
Status:active» by design

It would be VERY easy to do this...
In the source, find the node_quick_find_autocomplete function. This holds the two queries used in this module. This module can either pick from ALL node types or SELECTED node types - hence the two queries. You'll see in both that filter is "%s%%". The %s represents the string you entered. The %% will get reduced to a single % symbol. This produces something like foobar% which, if you know your mysql, means "anything beginning with foobar".

If you want your "version" of this module to search WITHIN the string rather than just the beginning, you need to add a %% just before the %s.

WARNING: This is not a feature I will be implementing because by adding a wildcard to the beginning of the LIKE means that the Database can no longer use an index on that column and filters are reduced to manual lookups.

If we were to EXPLAIN the SELECT then we get something like this...

mysql> EXPLAIN SELECT title FROM node WHERE title LIKE 'test%';
+----+-------------+-------+-------+-----------------+-----------------+---------+------+------+--------------------------+
| id | select_type | table | type  | possible_keys   | key             | key_len | ref  | rows | Extra                    |
+----+-------------+-------+-------+-----------------+-----------------+---------+------+------+--------------------------+
|  1 | SIMPLE      | node  | range | node_title_type | node_title_type | 767     | NULL |   11 | Using where; Using index |
+----+-------------+-------+-------+-----------------+-----------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)

... Now if we were to put a wildcard at the beginning, look what happens...

mysql> EXPLAIN SELECT title FROM node WHERE title LIKE '%test%';
+----+-------------+-------+-------+---------------+-----------------+---------+------+------+--------------------------+
| id | select_type | table | type  | possible_keys | key             | key_len | ref  | rows | Extra                    |
+----+-------------+-------+-------+---------------+-----------------+---------+------+------+--------------------------+
|  1 | SIMPLE      | node  | index | NULL          | node_title_type | 781     | NULL |   53 | Using where; Using index |
+----+-------------+-------+-------+---------------+-----------------+---------+------+------+--------------------------+
1 row in set (0.00 sec)

I believe this shows that there are no possible keys...

NOTE This is what I BELIEVE to be true. I'm not a DBA or anything like that.

#2

bneel - May 6, 2008 - 20:02

Hi,
Thanks a lot for your help.
This works fine.
Thx again for your module.
Benjamin

 
 

Drupal is a registered trademark of Dries Buytaert.