/    Sign up×
Community /Pin to ProfileBookmark

Search engine theory question

Well I have this simple question. I dont want the code on “how to do this” or etc. I just want to see if my knowledge/logic is correct on this….

I am creating a search engine for a orginization. (It will be a priviate search engine with a log in to even search it) anyways this search engine is going to search a database of users, and two databases or more of files. Now my question boils down to this. When in the search bar they type in their “term” that they want to search or “keyword” what ever you want to call it; store that in a temp array and then search the three or more databases using the temp array that was created using their terms and then find any matches within the databases and return the results.

So my train of thought as you can sort of see in the code below is useing an exsisting database (Temp array ATM “[I]$files[/I]“) and then compare that database with their search results which are in the “$terms_array”. I was thinking of doing this the most simple way possible using the “[I]eregi()[/I]” function. Now to my understanding that function already creates a temp array called “[I]matches[/I]” so now would it be possible for me to simply just use a simple for loop to call out the array “[I]matches[/I]” and display the results that way? Or does the function “[I]eregi()[/I]” not compare or cannot compare array’s/database’s, as it can only compare a given string/pattern to a given expression or pattern of some kind?

[CODE]<?php
//temp array of fake search items for testing
$files = array (‘spiewnik’, ‘Choc biedy dwie’, ‘Do ojczyzny’, ‘El Bajo’,
‘krzyz’, ‘warta’, ‘sprawnosci’, ‘formy’, ‘chicago’, ‘dom harcerskie’);

//get info from form
$terms = addslashes($_POST[‘terms’]);

//explode search terms set to array terms
$terms_array = explode (‘ ‘, $terms);

//count number of terms in box from array for use in temp code to show
$array_count = count ($terms_array);

?>
<html>
<head>
<title>Warta Search Engine (BETA V1.0) – Results</title>
</head>
<body>
<h1>Results for search:</h1>
<p>Here are your search terms:
<br />
<?php echo($terms); ?></p>

<br />

<p>Search array:
<br />
<?php
//Loops through the array to show (temp to see if creating) terms stored in array for use)
for ($i = 0; $i <$array_count; $i++) {
echo $terms_array[$i]. ” “;}
?></p>
</body>
</html>[/CODE]

to post a comment
PHP

1 Comments(s)

Copy linkTweet thisAlerts:
@NogDogSep 27.2012 — eregi_*() functions would only be for strings existing within your PHP script, and in any case are now deprecated in favor of the preg_*() functions.

You would probably be better off doing the matching in your DB queries, and to make it at all efficient, you'd want to set up the searchable fields to be configured with a "fulltext" index (at least that's what it's called in MySQL), though you [i]could[/i] use the DBMS's regexp functions, but probably at a significant cost in processing time (you'd probably have to do full table reads). Alternatively, you might look into something like MongoDB or Solr as potentially a better performing option.
×

Success!

Help @UAL225 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 6.1,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @meenaratha,
tipped: article
amount: 1000 SATS,

tipper: @AriseFacilitySolutions09,
tipped: article
amount: 1000 SATS,
)...