Jump to content

Search Engine


dcole.ath.cx

Recommended Posts

  • Replies 52
  • Created
  • Last Reply

Top Posters In This Topic

They need to use a rendering engine to render the page. They could write their own, which would be a headache because they would have to parse the html and css, apply all of the styles and positions correctly, and execute the javascript to see if it changes how the page looks. But there are probably third party components that include rendering engines, I've just never looked into it so I don't know if there are.Everything that renders a page from HTML uses a rendering engine, and there is no "industry-standard" way to do it. It's the reason why pages look different on different browsers, because they have different engines. IE uses the Trident engine, Firefox, Mozilla, and Netscape use the Gecko engine, and Opera has been using the Presto engine since version 7, when it replaced the Elektra engine.If you want to integrate an engine into something else, you can probably use either the Gecko engine, or the KDE KHTML engine, which Safari also uses. Both of them are open source.Also, to dcole, about the arrays, you will either want to use array_merge or the plus operator to merge the arrays, depending on if you want to keep the keys or reindex the array. See this example:http://manchine.net/w3/array.phpAnd for your second question, what you did is correct. If you aren't sure, you can use var_dump or print_r to show you the contents of the array.

Link to comment
Share on other sites

You can use array_merge if you want the array indexes to be renumbered:$result = array_merge($array1, $array2, ...); //renumbers keysor plus if you want to keep your numeric keys to be the same (not to change the keys). That's what the online example shows the difference, the 2 result arrays have new, renumbered keys, or the original keys.$result = $array1 + $array2; //keeps numbered keysBut either way will be faster than writing your own loop.

Link to comment
Share on other sites

so:$data1 = 1, 2, 3, 4; (each #, being a set in the array)$data2 = 5, 6, 7, 8; (each #, being a set in the array)$result = array_merge($data1, $data2);$result = 1, 2, 3, 4, 5, 6, 7, 8;This is what will happen?---- ---Now this is something later on... needle and haystack are arrays and I want to remove any set in needle from haystack! How do I do that?? btw, is is already in 2 for statements going though and compairing each set to another set!...if(in_array($needle, $haystack)){ WHAT GOES HERE}...so do I just put in some php function that will remove the current set in haystack?

Link to comment
Share on other sites

I think the array merge works moreover like this:$data1[0] = "1";$data1[1] = "2";$data1[2] = "3";$data1[3] = "4";$data2[0] = "5";$data2[1] = "6";$data2[2] = "7";$data2[3] = "8";$result = array_merge($data1, $data2);And what do you mean remove the current set from the haystack? Do you want to delete certain words or something?

Link to comment
Share on other sites

This is the difference between array_merge and the plus operator:

$array1[0] = "a0";$array1[1] = "a1";$array1[2] = "a2";$array1[3] = "a3";$array2[10] = "b0";$array2[11] = "b1";$array2[12] = "b2";$array2[13] = "b3";$merge1 = array_merge($array1, $array2);$merge2 = $array1 + $array2;/*$merge1:0 => a01 => a12 => a23 => a34 => b05 => b16 => b27 => b3$merge2:0 => a01 => a12 => a23 => a310 => b011 => b112 => b213 => b3*/

You can either use unset to delete a specific array element, or you can use array_diff to create an array that is the difference between 2 or more arrays, or only the elements from the first array that do not appear in the second. You can create an array of elements to remove from the first array, and then call array_diff to remove them all from the first array. array_diff will not include elements present in the second array that are not present in the first, only elements in the first that are not present in any of the others. The opposite is array_intersect, which returns an array containing only the elements from the first array that are present in all of the other arrays. You can use array_diff_key or array_intersect_key if you want to compare keys instead of values. If your array that you remove elements from starts as a numeric array:$array[0] = "a0";$array[1] = "a1";$array[2] = "a2";$array[3] = "a3";And you remove an element, say element 2, using either unset or array_diff, and want to re-index the array so that the keys are numbered consecutively (instead of skipping from 1 straight to 3, since you removed 2), you can just call array_merge with the one array and it will be re-indexed consecutively.

Link to comment
Share on other sites

okay, so now I have kept the data I want to and removed the unwanted data... so now I have to combine each term array and sort it from Found In Most Arrays to Found in Least Amount Of Arrays.so I have arrays like:$data1$data2$data3$data4then each set in each of thoughs arrays will be put in "results":(# of arrays found in) (rank) (URL) (data#),(data#),(data#)...(# of arrays found in) --- this is the number of $data# it is found in...(rank) -- this is a given rank I already have(URL) -- this is a given URL I aready have(data#),(data#),(data#)... -- for each (# of arrays found in), this will tell me what ones!so if I find data in $data1 and $data3 it will look like: 2 98 http://example.com 1,3or if I find data in $data1, $data2, and $data4 it will look like: 3 98 http://example.com 1,2,4---- ---How should I do this? I think I should make 4 result arrays so I can access any data real fast..[1](# of arrays found in) [2](rank) ____[3](URL) ____[4](data#),(data#),(data#)...[1]($results1) _________[2]($results2) [3]($results3) [4]($results4)1. for (each $data#) (call the count $a)2. for (each set in the $data array)3. explode by space4. check to see if URL is in $results3, if it is $results1++ and $results4 .= ",$a";else add to end of each $result with the correct data..

Link to comment
Share on other sites

If you put it in 4 different arrays, sorting will be a nightmare. You should probably use a multidimensional array, and then a user-defined sorting function using usort.$results[] = array('count' => $count, 'rank' => $rank, 'url' => $url, 'source' => $data);It's easy enough to access anything.$results[$i]['url'];sorting would be something like this:

function compare_links ($a, $b){  if ($a['rank'] == $b['rank'])   {	return 0;  }  return ($a['rank'] < $b['rank']) ? -1 : 1;}usort($results, "compare_links");

Link to comment
Share on other sites

but for my sorting I want to sort by $count, then by $rank, then by $urlso it's like4 13 g.com4 12 a.com3 45 d.com3 45 e.com2 10 c.com2 10 f.com1 90 z.comso what is the best way to sort it? I need to sort from high to low, then high to low, the A to Z.well, where there is return 0; I can just have it search the next array... but will it move it correctly. Doesn't the multidimensional array look like $array($array_of_count, $array_of_rank_, $array_of_url, $array_of_list); so how will the correct rank, url, and list stay together? the first line would be $array[0][0], $array[1][0], $array[2][0], $array[3][0];maybe I'm just lost...

Link to comment
Share on other sites

Yeah, I think you're a bit lost. The array is only 2 levels deep. You have this array for each item:$item['count'];$item['rank'];$item['url'];$item['source'];This is a single-level array with 4 elements. If you add this to your main array, then the main array with be 2 levels deep. The first level will choose which item, and the second level will choose which piece of the item.$results[7]['rank'];$results[7]['count'];$results[7]['url'];$results[7]['source'];etc. You know it's only 2 levels deep because there are only 2 indices there, there is the number that just says which item it is, and the string which says which attribute of that particular item.As for sorting, this is the comparison function I used:

function compare_links ($a, $b){  if ($a['rank'] == $b['rank'])   {	return 0;  }  return ($a['rank'] < $b['rank']) ? -1 : 1;}

You will want to edit the part where the ranks are equal to add the other comparisons. The comparison function takes 2 parameters (item A, and item B). It should return 0 if they are equal, a value less than 0 if A should come before B, and a value greater than 0 if A should come after B. So, edit the part where the ranks are equal and have it test the next thing, and if those are equal test the next thing etc. Just have it return less than 0 if A comes before B, greater if A comes after B, and 0 if they are equal.Also, you can still compare strings with < and >. The statement ('a' < 'z') is true.

Link to comment
Share on other sites

lets use this as an example:

<?php$a = array (1, 2, 3);$b = array (4, 5, 6);$c = array (7, 8, 9);$z = array ($a, $b, $c);print $z[0][0];print "and";print $z[0][1];print "and";print $z[0][2];?>

that will print 123, but I want to keep 147 inline with each other... so does usort move each set(the numbers) in each set($a, $b, $c) one?so it will move a set in $a one, move a set in $b one, and move a set in $c one?

Link to comment
Share on other sites

in_array will work if you can search for the entire subarray. It won't work if you only want to search for one element of the subarray. You could probably get creative with array_walk, but it would be similar to a loop.

Link to comment
Share on other sites

will it work for checking the 2nd set in every sub array... it's also the whole set... it would be like finding 2 in $z... it would check $z[0][1], then $z[1][1], then finally $z[2][1] ???$z[0][1] is 2, as $z[1][1] and $z[2][1] are 5 and 8

Link to comment
Share on other sites

No, in_array is not recursive. You can search for an entire array, like you can search $z for array(2, 4, 'www.google.com', '5,6'), but all in_array does is search a single array for an item, whether that item is another array or a scalar value. If you want to search recursively, you would probably want to write your own recursive search function that uses is_array to check for nested arrays and in_array to search nested arrays.

Link to comment
Share on other sites

well I need to change data too so maybe a loop would be best!php needs to make a grid_multidimensional_array type thing... where it's like an array but you can access any way you want at anytime... just by changing stuff after the variable name... but not like a (SQL) DB where you have to read and write, open and close...

Link to comment
Share on other sites

You can already access any array element at any time, that's the point of an array, but there is not a built-in recursive search function. You can write your own, which isn't too difficult, or if you want to manipulate the data some way you can use array_walk to apply your own function to each element in the array, which will probably be quicker than a loop.

Link to comment
Share on other sites

		function compare_links ($a, $		{			if ($a['count'] == $b['count'])			{				if ($a['rank'] == $b['rank'])				{					if ($a['url'] == $b['url'])					{						return 0;					}					return ($a['url'] > $b['url']) ? -1 : 1;				}				return ($a['rank'] > $b['rank']) ? -1 : 1;			}			return ($a['count'] < $b['count']) ? -1 : 1;		}		usort($results, "compare_links");

I need help here... that script above need to be fixed or maybe it's right... dnkI have an array $results, each set is an array 4 sets long (0-3)so the count for the first result is $result[0][0], rank is $result[0][1], and url is $result[0][2]now I want to order 'count' from highest to lowest, then if it's a tie order 'rank' from highest to lowest, and if 'rank' is a tie... order 'url' alphabetically.

Link to comment
Share on other sites

The sort function is fine. But if you have this array:array('count' => xx, 'rank' => xx, 'url' => xx)You cannot refer to count with index [0]. It's not the same thing. 0 is 0, 'count' is 'count'. If you are storing your array using numeric keys, then you need to access the elements using numeric keys in the comparison function. Technically, in PHP all arrays are associative, but by default the keys are ordered numerically. It is not type-strict associativity, the element 0 is the same as the element '0'. But you can't access the first named element with [0], unless the first element is [0].

Link to comment
Share on other sites

I new that much but I was lost with $a and $b... what do they need to be in terms of $resultsso do I just go $a = $results;I don't need to mess with $b, it will just know?also what about the other sets count, rank, and url ... because it's $a['count'] but for me that would be $a[all][0] do I need to name each set that's in the inner array so it know the difference?

Link to comment
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

×
×
  • Create New...