PDA

View Full Version : Internal search engine


asthyanax
09-14-2002, 06:38 PM
Hi,

I'l a french newbie and i really need help. I'm developping a delphi application and i'm making the help page on a website. Of course i would like to permit the user to search terms on it. I don't want to use asp or php for many reasons and i found something that could be fine for me in photoshop help.If someone could help me for understanding how it works.
Here's an exemple of the code used :

var dbFilesArr = new Array("","","","","","","","","","","","","","","","","","","","","","","","","","","",""
,"","","","","","","","","","","","","","","","","","db_45.htm","db_46.htm",""
,"db_48.htm","db_49.htm","db_50.htm","db_51.htm","db_52.htm",
"db_53.htm","db_54.htm","db_55.htm","db_56.htm","db_57.htm",
"db_58.htm","","","","","","","","","","","","","","","","","","","","","","",
"","","","","","","","","","","","","","","...etc);

and in each page (db_55.htm.....db_100.htm) :

var words = new Array("différent","disparition","disposition",..etc):
words["différent"] = "18-1,23-1,53-1,87-2,132-2,197-4,212-1,257-2,
258-1,321-1,445-1,446-1,457-2,497-1,509-1,517-1,535-2,588-1,609-5,648-1,748-1";
words["disparition"] = "193-2";
words["disposition"] = "78-1,121-1,122-2,123-10,332-1,352-1,383-5,
384-1,591-1,672=11,675-2,699-1";
words["dissemblable"] = "261-1,264-1";
words["dispersion"] = "259-1,26............etc


Thank's !

Chris
asthianax@yahoo.com

ASAAKI
09-15-2002, 02:16 PM
Ahem ... well ... it doesn't look very clear at the moment. a little digging around the code might help, but it'll take a while.
At any rate, you might find this helpful in the meantime:
http://www.javascriptkit.com/script/cutindex14.shtml

asthyanax
09-15-2002, 02:31 PM
Thank's for your response. Her's the entire page if you want to have a look; thank you very much.

Chris

ASAAKI
09-19-2002, 10:08 PM
Okay, I finally managed some time to take a look at it today.
Actually the Help.css has nothing to do with the search.
CSS (Cascading Style Sheets) is used just for the look (colors, fonts, etc) of the page,
it hasn't got anything to do with how things function.
I happen to have Photoshop myself, so I went into the Help
folder and looked into the db_x.js file .. that's the file with the
real searching functions. I've pasted it all at the end of this post
(for people who're a lot better at js than poor me to actually
crack it :D). You can make it out mainly by just looking at the comments.

Looking at it myself, this is what I think it's basically all about:
each of the db_nn.htm files is a file which deals with a
specific word, or rather ASCII letter, according to what search word the user enters.
the c...htm files are the main content files, the files that should
show up after the search.
the db_ files each have a list of words starting with the same
ASCII character as the user's search word. For example, if the user entered A,
and the corresponding ASCII version of the letter
A is 256 (I don't know if it is, let's just suppose it is), then one whole db_...htm file has a words[] array
that lists everything in the c...htm files that starts with ASCII 256.
on entering a search word:
separating and processing different letters of the search word to
get their ASCII code, u get the index of the db_... file to use. once
in the file, a search is performed to see if the search word exists
in that file's words array. each of the words[n] in the words array
in each of the db files is a list of words to be found that match the
first ascii letter of the search word. Each word in this words[]
array houses its own array, a list of indices of c_....htm files that
contain the word. the indices themselves somehow point to
these c..files, but i didn't figure out how.

after the results, i guess the db_...file is shown in the results
frame, with each of the indices within the search word[]'s (index)
array, now somehow converted into link-form, to link the user to
the appropriate c...page ... still awake? wow.

i guess the adobe people made up conventions and sliced up the
file names and search words to come up with the right files, but
u cud just do it simply. make ur own db_1,2...files, each db_file
containing its own words[] array, but each index[] in the words
array could be named simply after the file name of the
appropriate content page, no scripting needed to convert them.
Using this idea, I sort of made an example search thingie,
with one mydb_a.htm file as the db file that deals with search words starting with the letter 'A'
(u can only search for the words "apple", "apache",
and "address" in this example. entering
another a-word will give 'no results found'; entering a word that
starts with a different letter won't work at all). the c_...htm files
are the content files (yea i know the content files are crap,
but there needs to be some content!). the help.htm is the
main page with all the frames in it.
sorry my example is pretty crude ...
doesn't even bring up the titles of the matched documents ... it's
just built on a hunch and i did it up quickly (i cudn't so much as
remember booleans!!), but it oughta get a newbie going somewhere... i hope.


Here's the code from db_x.js, I guess some
proper javascripty person can figure the whole thing out :D :

var timer;
var timer2;
function PreLocalSearch(){
timer = setTimeout( "localSearch()", 10 );
}
function localSearch(){
var index;
var searchTerm;
var matchStr;
var fileIndicesArr;
var dbSliceFile;
var firstLetterIndex;
var fileIndexExpr;
var indexPartsArr;
var leftPart, rightPart; // Clear the timer
clearTimeout( timer );
// Get the passed-in index (corresponding to which search
expression word we are now on)
index = location.search.substr(1, location.search.length);
index = top.frames["Help_left"].glob_NdxCurrentWord++;
// Get the search word corresponding to this index.
searchTerm = top.frames["Help_left"].allSearchTerms[index];
// Trim it to the maximum length
searchTerm = searchTerm.substring(0,12);
// See if the (current) search term/word is found in this file's "words" array
if( words[searchTerm] ) {
//.....Get the list of file indices associated with this word...
matchStr = words[searchTerm];
//.....Split this list into separate file indices
fileIndicesArr = new Array();
fileIndicesArr = matchStr.split(",");
// each entry: n-m or n=m (n:file index & m:count) (- is non-title)
// (= is title)
//.....Process each file index, bumping the 'indexHitsArr' as we go..
for( var ndx = 0; ndx < fileIndicesArr.length; ndx++ ) {fileIndexExpr = fileIndicesArr[ndx];
if( fileIndexExpr.indexOf("-") != -1 ) {
// NON-TITLE HIT-------------------------------------------------
indexPartsArr = fileIndexExpr.split("-");
leftPart = parseInt(indexPartsArr[0]);
rightPart = parseInt(indexPartsArr[1]);
if( top.frames["Help_left"].rankHitsArr[leftPart] >= 0 ) {
top.frames["Help_left"].rankHitsArr[leftPart] += rightPart;
else {
top.frames["Help_left"].rankHitsArr[leftPart] -= rightPart;

}
}
else {

// TITLE HIT-----------------------------------------------------
indexPartsArr = fileIndexExpr.split("=");
leftPart = parseInt(indexPartsArr[0]);
rightPart = parseInt(indexPartsArr[1]);
if( top.frames["Help_left"].rankHitsArr[leftPart] >= 0 ) {
// Make negative & subtract count
top.frames["Help_left"].rankHitsArr[leftPart] =
0 - top.frames["Help_left"].rankHitsArr[leftPart] - rightPart;
}else {
top.frames["Help_left"].rankHitsArr[leftPart] -= rightPart; }
}
top.frames["Help_left"].indexHitsArr[leftPart]++; }
//.....See if we are done processing all of the search words/terms..
if( top.frames["Help_left"].glob_NdxCurrentWord >=
top.frames["Help_left"].allSearchTerms.length ) {// We are done.
PreCallShowResults();
return;
}
//Prepare for and execute the processing of the next search word

firstLetterIndex =
top.frames["Help_left"].allSearchTerms[top.frames["Help_left"].glob_NdxCurrentWord].charCodeAt(0);
dbSliceFile = top.dbFilesArr[firstLetterIndex];
if( dbSliceFile.length > 0 ) { // Our NEXT entered word starts
//with a letter that has a
//corresponding search db "slice"
// Handle the next "DAISY CHAIN" step.
top.frames["search_cache"].location = dbSliceFile; }
else {
// Our first entered word starts with a letter
// not represented by any search db "slice"
top.frames["Help_left"].searchResults_FAIL();
}
}
else { // NO MATCH FOUND ^^^^^
top.frames["Help_left"].searchResults_FAIL(); }}
function PreCallShowResults(){
timer2 = setTimeout( "callShowResults()", 10 );
}
function callShowResults(){
top.frames["Help_left"].assessFinalSearchResults();
clearTimeout( timer2 );
}

ASAAKI
09-19-2002, 10:13 PM
i just took another look at the other files in the photoshop's Help folder and saw there's this HelpSearchfset.htm file that's a pretty important part of the search as well. check out the other files to see the whole picture.

asthyanax
09-21-2002, 05:15 PM
thank's a lot for your help ASAAKI !!