Author Topic: [Tutorial] Making additional field searchable  (Read 149548 times)

0 Members and 1 Guest are viewing this topic.

Offline Ofuuzo

  • Newbie
  • *
  • Posts: 29
    • View Profile
[Tutorial] Making additional field searchable
« on: August 06, 2002, 05:21:37 PM »
- first only a englisch version ...
- eine deutsche Version kommt bald ... oder spšter ... ;) ... zwischenzeitlich nutze diese Deutsche-Google-‹bersetzung ...



I have added a field to the database to show not only the keywords, description, date ... . How can I make it searchable just like keywords, and description fields?

Thanks.

- Ofuuzo
« Last Edit: July 03, 2008, 01:12:26 AM by mawenzi »

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
[Tutorial] Making additional field searchable
« Reply #1 on: August 06, 2002, 05:43:40 PM »
In this example, i presuppose that you have added a new field called image_photographer.


1. Create a new column in the table 4images_wordmatch called photographer_match
Code: [Select]
ALTER TABLE 4images_wordmatch ADD photographer_match TINYINT(1) DEFAULT '0' NOT NULL;

2. †Open includes/search_utils.php and find this part
Code: [Select]
$search_match_fields = array(
 †"image_name" => "name_match",
 †"image_description" => "desc_match",
 †"image_keywords" => "keys_match"
);
add a new line to the array:
Code: [Select]
$search_match_fields = array(
 †"image_name" => "name_match",
 †"image_description" => "desc_match",
 †"image_keywords" => "keys_match",
 †"image_photographer" => "photographer_match"
);
Note the comma added behind the third line!


3. Open main.php in your lang folders and add a new line:
Code: [Select]
$lang['image_photographer_only'] = "Only Photographer";Do this for all your languages!


4. Open the template search_form.html and add this:
Code: [Select]
<input type="radio" name="search_fields" value="image_photographer" /> {lang_image_photographer_only}

5. Rebuild the search index.
You can use the plugin from here.

Greets Jan
« Last Edit: March 16, 2005, 12:36:49 AM by V@no »
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Ofuuzo

  • Newbie
  • *
  • Posts: 29
    • View Profile
[Tutorial] Making additional field searchable
« Reply #2 on: August 07, 2002, 12:19:16 PM »
That is great great great!!!,

Thank you very very much.

- Ofuuzo

Offline Dmitro

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Keywords mistery
« Reply #3 on: September 01, 2002, 01:08:19 PM »
Jan,

I have done all what you wrote above to make one of the fields searcheable. All should be fine, but, I have a misterious problem with some of my keywords:

Short keywords such as 16, 17, 18 do not return any records, while other keywords (longer numbers, such as 1666 and words such as violin, braccio etc ) make the job without any trouble.

What is the problem?

Thanks, indeed.

Dmitry
Regards,
Dmitry
____________________
www.violadabraccio.com

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
[Tutorial] Making additional field searchable
« Reply #4 on: September 01, 2002, 01:36:26 PM »
If you use version 1.7 you can define the min and max searchword length in "includes/constants.php".

Code: [Select]
define('MIN_SEARCH_KEYWORD_LENGTH', 3);
define('MAX_SEARCH_KEYWORD_LENGTH', 25);

After changing that, please rebuild your searchindex.

Greets Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Dmitro

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
[Tutorial] Making additional field searchable
« Reply #5 on: September 01, 2002, 01:43:38 PM »
Dear Jan,
Thanks a lot for your quick reply!
I am not yet using 1.7  - I am still checking how much work I have to do in order to upgrade.
Dmitry
Regards,
Dmitry
____________________
www.violadabraccio.com

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
[Tutorial] Making additional field searchable
« Reply #6 on: September 01, 2002, 01:52:29 PM »
Search for
Code: [Select]
if ($word != "" && strlen($word) > 2 && strlen($word) < 26 && !in_array($word, $stopword_list)) {
in "includes/search_utils.php" and
Code: [Select]
elseif ($split_words[$i] != "" && strlen($split_words[$i]) > 2 && strlen($split_words[$i]) < 26 && !in_array($split_words[$i], $stopword_list)) {
in "search.php" and change "2" to "1".

Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline Dmitro

  • Jr. Member
  • **
  • Posts: 59
    • View Profile
Jan is a magician
« Reply #7 on: September 01, 2002, 02:44:47 PM »
Jan, you are a magician.
Thanks. Dmitry :D
Regards,
Dmitry
____________________
www.violadabraccio.com

Offline k4nth

  • Newbie
  • *
  • Posts: 28
    • View Profile
[Tutorial] Making additional field searchable
« Reply #8 on: January 28, 2003, 11:06:34 AM »
is it possible to include Categories names in search?

Offline Jan

  • Administrator
  • 4images Guru
  • *****
  • Posts: 5.024
    • View Profile
    • 4images - Image Gallery Management System
[Tutorial] Making additional field searchable
« Reply #9 on: January 28, 2003, 03:32:30 PM »
No.

Jan
Your first three "must do" before you ask a question:
1. Forum rules
2. FAQ
3. Search

Offline bernd

  • Full Member
  • ***
  • Posts: 214
    • View Profile
how can i have the image_photographer clickable?
« Reply #10 on: March 22, 2003, 09:42:17 PM »
to be able to use it just like the keywords? I did the MODs so I have the photographer being shown below the image and I can search for this via the extended search but I'd like my users to be able to just click the photographer's name and they are then shown all pictures taken by this guy.

I tried to find how/where it is done for the keywords but I struggled ...

Thanks in advance!
Bernd

Offline Psy

  • Pre-Newbie
  • Posts: 5
    • View Profile
[Tutorial] Making additional field searchable
« Reply #11 on: March 28, 2003, 01:40:25 PM »
I'm having problems with making these fields searchable

I used the Mod to add extra fields ( 7 extra fields in total ) which worked fine...all the new fields dumped into the db fine and displayed fine.

Next, I followed this Mod to make these new fields searchable, and ran the rebuild search index tool,
witch gave me this error:

Code: [Select]
Processing image qqqqq, ID 9 ... OK
Processing image can, ID 10 ...
DB Error: Bad SQL Query: REPLACE INTO 4images_wordmatch (image_id, word_id, name_match, desc_match, keys_match, edibility_match, habitat_match, range_match, season_match, sporecolor_match, mushroomshape_match, lookalikes_match) VALUES (10, 7, 0, 1, 1, 0), (10, 10, 0, 0, 1, 0)
Column count doesn't match value count at row 1
OK
Processing image asasas, ID 11 ...
DB Error: Bad SQL Query: REPLACE INTO 4images_wordmatch (image_id, word_id, name_match, desc_match, keys_match, edibility_match, habitat_match, range_match, season_match, sporecolor_match, mushroomshape_match, lookalikes_match) VALUES (11, 12, 0, 0, 0, 0), (11, 13, 0, 0, 0, 0), (11, 14, 0, 0, 0, 0), (11, 15, 0, 0, 0, 0)
Column count doesn't match value count at row 1
OK


Search index rebuilt!





I them tried search my new fields, and found that I can search the first extra field I added, get a error when I try to search the rest of the new fields:
Code: [Select]
DB Error: Bad SQL Query: SELECT m.image_id FROM 4images_wordlist w, 4images_wordmatch m WHERE w.word_text LIKE 'rust' AND m.word_id = w.word_id AND m.sporecolor_match = 1
Unknown column 'm.sporecolor_match' in 'where clause'



I them tried to upload a new image, and got this error:
Code: [Select]
DB Error: Bad SQL Query: REPLACE INTO 4images_wordmatch (image_id, word_id, name_match, desc_match, keys_match, edibility_match, habitat_match, range_match, season_match, sporecolor_match, mushroomshape_match, lookalikes_match) VALUES (12, 5, 0, 0, 0, 1), (12, 12, 0, 0, 0, 0), (12, 13, 0, 0, 0, 0), (12, 14, 0, 0, 0, 0), (12, 15, 0, 0, 0, 0)
Column count doesn't match value count at row 1



Can anyone tell me what I'm doing wrong? I understand that this error comes from adding different amount
of values in than there are columns, but I can't see where my error is....any ideas????
Code: [Select]
    Quote
    [/list:u]

    Offline Chris

    • 4images Moderator
    • 4images Guru
    • *****
    • Posts: 4.487
    • Did u ever stop to think and then forget to start?
      • View Profile
    [Tutorial] Making additional field searchable
    « Reply #12 on: March 28, 2003, 02:44:53 PM »
    "Column count doesn't match value count at row 1"

    It looks to me like you have a mismatch in the number of fields you added to includes/db_field_definitions.php and the number of new database columns you created.  Recheck these.  Either that or you have a mismatch of the types.  IE:  You added a character field and an integer field in the php file but added an integer and then character column in the database table.

    Offline Psy

    • Pre-Newbie
    • Posts: 5
      • View Profile
    [Tutorial] Making additional field searchable
    « Reply #13 on: March 28, 2003, 10:06:40 PM »
    Chris - thanks for the quick reply

    I've checked everything over 100 time and I still can't see anything wrong. What really gets me is that the first search field I added still works fine, but the rest don't.  :x  :x  :x  :x  :x  :x
    Anyone have any other ideas???????? Plaese :cry:

    Offline V@no

    • If you don't tell me what to do, I won't tell you where you should go :)
    • Administrator
    • 4images Guru
    • *****
    • Posts: 17.849
    • mmm PHP...
      • View Profile
      • 4images MODs Demo
    [Tutorial] Making additional field searchable
    « Reply #14 on: March 28, 2003, 11:26:56 PM »
    I didnt follow the discussion here :? but, just a thought:
    Quote
    DB Error: Bad SQL Query: REPLACE INTO 4images_wordmatch (1 image_id, 2 word_id, 3 name_match, 4 desc_match, 5 keys_match, 6 edibility_match, 7 habitat_match, 8 range_match, 9 season_match, 10 sporecolor_match, 11 mushroomshape_match, 12 lookalikes_match) VALUES 1 (12, 5, 0, 0, 0, 1), 2 (12, 12, 0, 0, 0, 0), 3 (12, 13, 0, 0, 0, 0), 4 (12, 14, 0, 0, 0, 0), 5 (12, 15, 0, 0, 0, 0)
    Column count doesn't match value count at row 1

    colored numbers are just count how many fields u are tryin  to update, and how many values. so, I'd say that the mismatch: 12 fields, but only 5 of them set values.
    Your first three "must do" before you ask a question:
    Please do not PM me asking for help unless you've been specifically asked to do so. Such PMs will be deleted without answer. (forum rule #6)
    Extension for Firefox/Thunderbird: Master Password+    Back/Forward History Tweaks (restartless)    Cookies Manager+    Fit Images (restartless for Thunderbird)