PhpDig.net

Go Back   PhpDig.net > PhpDig Forums > How-to Forum

Reply
 
Thread Tools
Old 02-06-2004, 07:06 AM   #1
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
What's in a word for 1.8.0?

I'm just beginning with 1.8.0...

The doc states: "Characters '._~@#$:&%/;,=- now allowed in indexing and searches".

A first test seems to indicate that "word1;word2;word3;...", which was considered as separate words in 1.6.5, is now considered as one. Therefore I no longer find the page when searching word2. Moreover, as in my website the combination always grows beyond 30 characters, it is not indexed, which means that I cannot find the page when searching word1 either!

Is this indeed a changed behavior in 1.8.0? Why was it changed in this way? Is there a config parameter for it?

This has other "funny" impacts: if I have a phrase "... word1, word2 ..." in my webpage, I won't find it back with an exact phrase search "word1 word2", I have to search for "word1, word2", with the comma, to find it! (I've tested it.) Are you sure that this is what people expect as behaviour?
__________________
René Haentjens, Ghent University
renehaentjens is offline   Reply With Quote
Old 02-06-2004, 10:03 AM   #2
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
Hi. A cool aspect of GNU/GPL software is that users get the source code free so they can change it to fit their individual needs. If you want to remove all or some of the ._~@#$:&%/;,=- characters, just do the following and then reindex.

In search_function find and modify the following as desired:

$what_query_chars = "[^".$phpdig_words_chars[PHPDIG_ENCODING]." \\'.\_~@#$:&\%/;,=-]+";

In phpdig_functions.php find and modify the following as desired:

$text = ereg_replace('[^'.$phpdig_words_chars[$encoding].' \\'._~@#$:&%/;,=-]+',' ',$text);

In robot_functions.php find and modify the following as desired:

if (strlen($key) > SMALL_WORDS_SIZE and strlen($key) <= MAX_WORDS_SIZE and !isset($common_words[$key]) and ereg('^['.$phpdig_words_chars[PHPDIG_ENCODING].'#$]',$key))
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-09-2004, 01:04 AM   #3
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Thanks, Charter. Indeed GNU/GPL has this "extralegal benefit" but you have to know what you're doing or get a little help from someone who does!

The piece of code from robot_functions seems to say: insert in database if the word is not too small or too large, if it is not a stop word, and if it starts with a "words_char" or a "#" or a "$". Wouldn't it be easier to simply add "#" and "$" to the default lists of $phpdig_words_chars in config.php?

For the rest of the special characters that are allowed in words (but not at the beginning) may I suggest an additional config parameter?

There is a little inconsistency with the backslash as could be expected from the fact that the two regexps (in search_function and in phpdig_functions) are not identical.

I haven't completely figured out why, but if a page contains "word1\word2", the separate words are indexed, but there is no way to find the page back by an exact match like for "word1\word2" or "word1 word2" or similar. Unless with CONTENT_TEXT = 0 in which case you can find it with exact match "word1 word2" (one day I'll have to understand what CONTENT_TEXT means...)
__________________
René Haentjens, Ghent University

Last edited by renehaentjens; 02-09-2004 at 01:14 AM.
renehaentjens is offline   Reply With Quote
Old 02-09-2004, 09:28 AM   #4
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> Wouldn't it be easier to simply add "#" and "$" to the default lists of $phpdig_words_chars in config.php?

Hi. TMTOWTDI, but # and $ are not word characters.

>> For the rest of the special characters that are allowed in words (but not at the beginning) may I suggest an additional config parameter?

Maybe, but then there may be issues with what to escape and where... read on.

>> There is a little inconsistency with the backslash as could be expected from the fact that the two regexps (in search_function and in phpdig_functions) are not identical.

In search_function.php the backslash allows escaping '_% from user input to make literal characters. In phpdig_functions the backslash escapes ' to prevent a parse error.

>> I haven't completely figured out why, but if a page contains "word1\word2", the separate words are indexed, but...

The '._~@#$:&%/;,=- characters are allowed in search results, no backslash.

>> ...what CONTENT_TEXT means...

Basically CONTENT_TEXT set to one stores text content from crawled pages in the text_content directory. With CONTENT_TEXT set to zero then first_words from the spider table is used.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-10-2004, 06:53 AM   #5
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Bear with me, Charter, I'm doing this with honorable intentions.

(I had to look up "TMTOWTDI", I'm not a Perl fan...)

Thanks for explaining CONTENT_TEXT. Now I wonder why anyone would want to set it on. Isn't using the DB *always* better than using a directory?

Concerning the backslash, I took a piece of the search_function code, added a line in front to simulate user input, and a line at the end to see the result of the code.

Here's the code:
<?php
$query_to_parse = addslashes('w5+6w*56[_ww5]:ww6°!w55(w66)w5w5\w6w6');


$query_to_parse = str_replace('_','\_',$query_to_parse); // avoid '_' in the query
$query_to_parse = str_replace('%','\%',$query_to_parse); // avoid '%' in the query
$query_to_parse = str_replace('\"',' ',$query_to_parse); // avoid '"' in the query
$query_to_parse = strtolower($query_to_parse); //made all lowercase

$what_query_chars = "[^w56 \'.\_~@#$:&\%/;,=-]+"; // epure chars \'._~@#$:&%/;,=-

$query_to_parse = eregi_replace($what_query_chars," ",$query_to_parse);
$query_to_parse = trim(ereg_replace(" +"," ",$query_to_parse)); // no more than 1 blank

echo htmlspecialchars($query_to_parse);
?>

Here's the output, scraped from my screen:
w5 6w 56 \_ww5 :ww6 w55 w66 w5w5\\w6w6

The backslash hasn't gone away... Shouldn't it have by now?
__________________
René Haentjens, Ghent University
renehaentjens is offline   Reply With Quote
Old 02-11-2004, 08:08 AM   #6
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> Now I wonder why anyone would want to set it on.

Hi. Only the first words from an indexed page are in the database table.

>> Isn't using the DB *always* better than using a directory?

http://discuss.fogcreek.com/joelonso...w&ixPost=99830
http://www.faqts.com/knowledge_base/...phtml?id=11839
http://lists.evolt.org/archive/Week-...08/109650.html

>> The backslash hasn't gone away... Shouldn't it have by now?

With unmodified version 1.8.0, when you index word1\word2 only word1 word2 are in the keywords table, no backslash. The backslashes in the PhpDig code are there for escaping purposes.

The following code will remove the backslashes from your example:

<?php
$query_to_parse = addslashes('w5+6w*56[_ww5]:ww6°!w55(w66)w5w5\w6w6');
$query_to_parse = str_replace('_','\_',$query_to_parse);
$query_to_parse = str_replace('%','\%',$query_to_parse);
$query_to_parse = str_replace('\"',' ',$query_to_parse);
$query_to_parse = strtolower($query_to_parse);
$text = ereg_replace('[^w56 \\'._~@#$:&%/;,=-]+',' ',$query_to_parse);
$query_to_parse = trim(ereg_replace(" +"," ",$text));
echo htmlspecialchars($query_to_parse);
?>
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-12-2004, 03:40 AM   #7
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Thanks Charter for being patient with me.

I understand your reply as follows:

For 1.8.0, in libs/search_function.php, replace the line:
$what_query_chars = "[^".$phpdig_words_chars[PHPDIG_ENCODING]." \'.\_~@#$:&\%/;,=-]+"; // epure chars \'._~@#$:&%/;,=-
by:
$what_query_chars = "[^".$phpdig_words_chars[PHPDIG_ENCODING].' \\'._~@#$:&%/;,=-]+'; // epure chars \'._~@#$:&%/;,=-

(The part after ENCODING]. reads: opening apostrophe, space, backslash-apostrophe, point, underline, ... - I'm having some trouble getting this into this forum post...)

Thanks for the pointers to the interesting debates on flat files vs. database. Of course the PhpDig case is different, because a database is already being used. The question then is why would anyone want to replace a table field which perfectly fits the purpose - you can always put a little bit more text in the field if needed - by a potentially very large number of files in one directory?

I'm biased, I admit. I have seen several cases in my career as developer where performance went drastically down when the application had to manage hundreds or thousands of little files in one directory, on Unix, Windows and other platforms. And we could never guarantee that the files would always remain in sync with the records in the database table...
__________________
René Haentjens, Ghent University

Last edited by renehaentjens; 02-12-2004 at 03:44 AM.
renehaentjens is offline   Reply With Quote
Old 02-13-2004, 09:41 PM   #8
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> For 1.8.0, in libs/search_function.php, replace the line...

Hi. It was code that would remove the backslashes from your example. The backslash in the search_function.php file is there for escaping purposes. Maybe the following links will help, or perhaps add a line in search_function.php that removes backslashes, but only if not followed by a character that should be escaped.

http://www.mysql.com/doc/en/String_syntax.html
http://www.mysql.com/doc/en/String_c...functions.html
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-16-2004, 03:57 AM   #9
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Charter, I may be a beginner with 1.8.0 and only recently promoted junior to member in this forum, I am not a novice on string literals!

The fact remains that, when looking at the mysql_query around line 217 in search_function:
1. with user query "abc!def" it is executed twice, with: (1) ... AND k.keyword like 'abc%' ... (2) ... AND k.keyword like 'def%', whereas
2. with user query "abc<backslash>def", it is executed once, with: ... AND k.keyword like 'abc<backslash><backslash>def%' ...
__________________
René Haentjens, Ghent University
renehaentjens is offline   Reply With Quote
Old 02-16-2004, 12:41 PM   #10
Charter
Head Mole
 
Charter's Avatar
 
Join Date: May 2003
Posts: 2,539
>> ...may be a beginner with 1.8.0 and only recently promoted junior to member in this forum, I am not a novice on string literals...

Hi. It seems you have taken offense where none was intended. Please keep in mind that, if I provide code or answer questions, I do so free of charge, on my own time, to be helpful.

>> The fact remains that, when looking at the mysql_query around line 217 in search_function...

Like I said, perhaps add a line in search_function.php that removes backslashes, but only if not followed by a character that should be escaped.

<?php

$query_to_parse = "I\'m_wearing_a%white%shirt\with\sleeves!";
$query_to_parse = addslashes($query_to_parse);

$query_to_parse = str_replace('_','\_',$query_to_parse);
$query_to_parse = str_replace('%','\%',$query_to_parse);
$query_to_parse = str_replace('\"',' ',$query_to_parse);

$what_query_chars = "[^ a-z0-9\\'.\_~@#$:&\%/;,=-]+";

$query_to_parse = eregi_replace("[\][^_%'\"]"," ",preg_replace('/[\0]/is',' ',$query_to_parse));
// TMTOWTDI $query_to_parse = eregi_replace("[\]{2}"," ",$query_to_parse);

if (eregi($what_query_chars,$query_to_parse)) {
$query_to_parse = eregi_replace($what_query_chars," ",$query_to_parse);
}

echo $query_to_parse; // I\\'m\_wearing\_a\%white\%shirt with sleeves

?>

If this method does not suit your fancy, then just rework the code to something that would be a palatable solution for you.
__________________
Responses are offered on a voluntary if/as time is available basis, no guarantees. Double posting or bumping threads will not get your question answered any faster. No support via PM or email, responses not guaranteed. Thank you for your comprehension.
Charter is offline   Reply With Quote
Old 02-18-2004, 03:37 AM   #11
renehaentjens
Orange Mole
 
Join Date: Nov 2003
Posts: 69
Thanks, Charter.

No offense taken! I appreciate your work and your advise, as I stated and will repeat every now and then in other posts. Talking to each other over a forum line isn't always that easy...

I should devote more time to understanding the code in order to know where I could do something about the d*** backslash.

Anyway, not so many users are going to put backslashes between query words. Why would they? It's only perfectionists like myself, with a never sleeping suspicion about possible havoc caused by funny characters, who try out such things.
__________________
René Haentjens, Ghent University
renehaentjens is offline   Reply With Quote
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Forum Jump

Similar Threads
Thread Thread Starter Forum Replies Last Post
Only searching from start of word benklocek Troubleshooting 1 03-18-2005 01:14 PM
Indexing "<word>-<word>"? FaberFedor How-to Forum 23 02-28-2005 03:35 AM
serach more than one word jjpcoca How-to Forum 1 06-19-2004 05:42 AM
Indexing word docs javajaga External Binaries 1 03-30-2004 08:19 AM
Directory structures appear as one word Big_ben How-to Forum 2 11-08-2003 10:21 AM


All times are GMT -8. The time now is 02:41 PM.


Powered by vBulletin® Version 3.7.3
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Copyright © 2001 - 2005, ThinkDing LLC. All Rights Reserved.