1

我希望我的网站有一个搜索栏,我的网站是用核心 PHP 创建的。

我网站的某些部分有静态页面,而某些部分有动态页面。

  1. 我的开发人员说不建议在 PHP 中构建一个可以在静态页面上工作的自定义搜索栏,因为它太慢了,因为它会进行文件夹内搜索。根据他的说法,定制的搜索栏只在动态页面上效果最好,因此我应该实现一个谷歌 API。

  2. 为什么我对构建 Google API 搜索框不感兴趣?因为我的开发人员无法自定义它的设计,并且标准框没有与我的网站设计融合。

关于如何做任何一点的任何建议或建议。

4

4 回答 4

2

如果将静态页面保存在数据库中,工作会更轻松

于 2014-11-25T07:53:49.337 回答
1
  1. 他是对的,这真的很慢。但是使用正确的缓存系统是有可能捕捉到这一点的。

  2. 谷歌搜索栏可以像这样稍微定制:http ://www.elitepvpers.com/forum/ 但我真的给了你一些很棒的功能和轻微的谷歌提升

于 2014-11-25T07:59:43.330 回答
0

Why don't clients trust their developers? He's absolutely right.

  1. A dynamic search through static pages would indeed require a search through the File System which is slow as hell (could be prevented by caching though).

  2. A google searchbar is not really customizable and that's not because "he was not able to do it", but because it's just restricted by Google. You use their products? You get their branding. It's as simple as that.

  3. PHP gives you the power to create dynamic websites. You just need to use it. If you store your content in a database you would have the advantages of a fulltext search which is great.

  4. If you've got a dead simple website consider to set up a XML (or whatever format you prefer) with the static content and link it with the URL of the actual page. That could look like this for example:

XML File

<?xml version="1.0"?>
<pages>
    <page>
        <url>http://google.com</url>
        <title>Some title</title>
        <content>
            The quick brown fox jumps over the lazy dog
        </content>
    </page>

    <page>
        <url>http://yahoo.com</url>
        <title>Ohai Catz</title>
        <content>
            The quick Cat kitten cat cat
        </content>
    </page>
</pages>

Sample PHP

<?php

// String to search for
$searchString = 'Cat';

$xml = simplexml_load_file('staticpages.xml');

$pageMatches = [];

foreach( $xml->page AS $page )
{
    // Check if the keyword exists in either the title or the content 
    if( stristr($page->content, $searchString) !== false || stristr($page->title, $searchString) !== false )
    {
        $pageMatches[] = $page;
    }
}
?>

<?php echo $searchString ?> has been found on the following pages: <br>

<?php foreach( $pageMatches AS $match ): ?>
    <a href="<?php echo $match->url ?>"><?php echo $match->url ?></a><br>
<?php endforeach ?>

Output

Cat has been found on the following pages: 
http://yahoo.com

The advantages of that approach:

  • No database
  • With small tweaks you could let the contents of your site be displayed from the XML, so you had a central source of your data
  • You could add additional information like tags or keywords to the XML to make the search more precise

Now the big disadvantage that instantly disqualifies this method for efficient searching:

  • You need to implement a search algorithm.

I simulated it with stristr(). If you want a search with usable results you have to put a lot of work and effort into it. Maybe you'll stumble upon some algorithms on the internet. But search algorithms are a science in it's own. Google isn't a multi-billion dollar company for nothing. Keep that in mind

于 2014-11-25T08:21:07.710 回答
0

就像 Jawlon Rodriguez 所说,您需要在数据库中为静态内容创建表格,将所有文本和 HTML、CSS、JS 内容保存在表格中,然后将其取出。更好更快。

于 2014-11-25T07:59:17.653 回答