Wrox Programmer Forums
|
SQL Language SQL Language discussions not specific to a particular RDBMS program or vendor.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the SQL Language section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
 
Old December 26th, 2009, 07:13 AM
Friend of Wrox
 
Join Date: Nov 2009
Posts: 156
Thanks: 13
Thanked 16 Times in 16 Posts
Default Advanced Search

here is a small sample to know a bit about search engines

Code:
-- create database for test

create database Test_Engine
GO


use Test_Engine;
GO

-- create main table

create table info(
  id bigint primary key identity(1,1),
  keyword nvarchar(50) not null,
  Description nvarchar(200) not null
)
GO


-- insert some records

insert into info (keyword, Description)
values ('ali','my interested name')
GO

insert into info (keyword, Description)
values ('abi','blue in persian')
GO

insert into info (keyword, Description)
values ('alias', 'other name')
GO

insert into info (keyword, Description)
values ('samane','girl name in Iran')
GO

insert into info (keyword, Description)
values ('samaneh','system in persian')
GO

insert into info (keyword, Description)
values ('samin','golden')
GO



-- create stored procedure for seaching 

create proc search
(
	@keyword nvarchar(50)
)
as
if exists (select id from info where keyword = @keyword)
begin
	select [description], UPPER(@keyword) + ' found' as report from info where keyword = @keyword
end
else
begin
	select [description], UPPER(@keyword) + ' not found. did you mean: ' + UPPER(keyword) + '?' as report from info 
	where SOUNDEX(keyword) = SOUNDEX(@keyword) or DIFFERENCE(keyword, @keyword) > 3
	UNION
	select '' as [description], UPPER(@keyword) + ' not found' AS report
	where @@ROWCOUNT = 0
end
GO




-- get searching time for some keywords - 
-- Test it in your system to get good results

declare @start datetime
set @start = CURRENT_TIMESTAMP

exec search 'ali'

exec search 'aly'
 
exec search 'samani'

exec search 'saeed'

declare @end datetime
set @end = CURRENT_TIMESTAMP


select 'Operation execution time', datediff(MILLISECOND, @start, @end), 'ms';
GO
if you want to know more send me an email : [email protected]

if this post was useful press THANKS button





Similar Threads
Thread Thread Starter Forum Replies Last Post
Where is Advanced Search ? MikeW2 BOOK: Beginning SharePoint 2007: Building Team Solutions with MOSS 2007 ISBN: 978-0-470-12449-9 2 August 13th, 2007 03:36 AM
ASP Advanced Search cancer10 Classic ASP Databases 11 October 17th, 2006 08:16 AM
advanced search Moharo Pro PHP 1 February 2nd, 2004 04:43 PM





Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
Copyright (c) 2020 John Wiley & Sons, Inc.