"Венчурные Интеллектуальные Проекты"
26 Апреля 2024, 05:19:55 *
Добро пожаловать, Гость. Пожалуйста, войдите или зарегистрируйтесь.

Войти
Новости:
 
   Начало   Помощь Войти Регистрация  
Страниц: [1]   Вниз
  Печать  
Автор Тема: Организация поиска по сайту  (Прочитано 3504 раз)
0 Пользователей и 1 Гость смотрят эту тему.
krakoss
Разработчик 2
Ветеран
***
Offline Offline

Сообщений: 600


Email
« : 15 Января 2013, 08:06:37 »

Пример взят с сайта http://code.msdn.microsoft.com/CSASPNETSearchEngine-52f5392c

==============================================================================
 ASP.NET APPLICATION : CSASPNETSearchEngine Project Overview
==============================================================================

//////////////////////////////////////////////////////////////////////////////
Summary:

This sample shows how to implement a simple search engine in an ASP.NET web site.

//////////////////////////////////////////////////////////////////////////////
Demo the Sample:

Open Default.aspx page, input one or more keywords into the text box.
Click the submit button.

//////////////////////////////////////////////////////////////////////////////
Code Logical:

1. Create the database.
   a. Create a SQL Server database named "MyDatabase.mdf" within App_Data folder.
   b. Create a Table named "Articles" in the database.

      ID       bigint (Primary Key)
      Title    nvarchar(50)
      Content  varchar(MAX)

   c. Input some sample records to the Table.

2. Data Access.
   a. Create a class named "Article" represents a record.
   b. Create a class named "DataAccess" to access database. This class contains
      public methods GetArticle(), GetAll() and Search(). Within Search() method,
      the key code is generating a complex Sql command which is used to search database.

        // Generate a complex Sql command.
        StringBuilder builder = new StringBuilder();
        builder.Append("select * from [Articles] where ");
        foreach (string item in keywords)
        {
            builder.AppendFormat("([Title] like '%{0}%' or [Content] like '%{0}%') and ", item);
        }

        // Remove unnecessary string " and " at the end of the command.
        string sql = builder.ToString(0, builder.Length - 5);
3. Search Page.
   The key controls of this page is TextBox control named "txtKeyWords" which
   is used to input keywords, and Repeater control which is used to display
   result.
   And there is a JavaScript function which is used to hightlight keywords
   in the result.

        for (var i = 0; i < keywords.length; i++)
        {
            var a = new RegExp(keywords, "igm");
            container.innerHTML = container.innerHTML.replace(a, "<span style='background:#FF0;'>$0</span>");
        }
4. The Detail Page.
   This page receives a parameter from Query String named "id", and then call
   DataAccess class to retrieve a individual record from database to show in the page.
   

//////////////////////////////////////////////////////////////////////////////

И готовое решение к нему в архиве. На основе которого можно организовать поиск по всему сайту  Подмигивающий
Записан
Страниц: [1]   Вверх
  Печать  
 
Перейти в:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2006-2009, Simple Machines Valid XHTML 1.0! Valid CSS!