Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Are there any better search methods instead of string.Contains("keyword") using asp.net?

For example, the users of our app want to search products by entering a keyword of productName.

The Products table of the sql server database contains about 10 million records.

Are there any better and higher-performance search methods to implement instead of productName.Contains("keyword") using asp.net C# ?

I'm using stored procedures now, but linq to sql or entity framework are also a possibility.

like image 751
Mike108 Avatar asked Apr 03 '10 06:04

Mike108


People also ask

Which of the following is used to open a table in a database in asp net?

Displaying Data from a Database. Once you've got a database with data in it, you can display the data in an ASP.NET web page. To select the table rows to display, you use a SQL statement, which is a command that you pass to the database.

What database does ASP Net use?

The Visual Studio web project templates use SQL Server for the ASP.NET membership database by default. Nearly all ASP.NET documentation on the MSDN web site, ASP.NET web sites, and in blog posts uses SQL Server.


2 Answers

If you want better performance then you could look into a full text search. Note that this is currently not supported by LINQ to SQL but you can write the SQL in a stored procedure and call the stored procedure from your application. The accepted answer for this StackOverflow post recommends reading this article.

like image 187
Mark Byers Avatar answered Sep 26 '22 12:09

Mark Byers


Well you could achieve this from the db side using a LIKE

LIKE (Transact-SQL)

Something like

DECLARE @Table TABLE(
        Val VARCHAR(50)
)

INSERT INTO @Table SELECT 'asdf'
INSERT INTO @Table SELECT 'tada'
INSERT INTO @Table SELECT 'foo'
INSERT INTO @Table SELECT 'bar'
INSERT INTO @Table SELECT 'test'
INSERT INTO @Table SELECT 'test foo'

DECLARE @Lookup VARCHAR(50)
SELECT @Lookup = 'foo'

SELECT  *
FROM    @Table
WHERE   Val LIKE '%' + @Lookup + '%'
like image 23
Adriaan Stander Avatar answered Sep 24 '22 12:09

Adriaan Stander