TeaDrinkingGeek
TeaDrinkingGeek

Reputation: 2023

Creating a search functionality in ASP.NET

I have a website, that content (HTML) is generated using ASP.NET C# from an SQL Server database.

Now I want to add a search function on the website so users can search the content. It would bring up a results page with results.

What is the best way to do this?

Upvotes: 11

Views: 9106

Answers (9)

Lars Holdgaard
Lars Holdgaard

Reputation: 9966

The 2 best solutions:

  • Google Custom Search (GCS)
  • SQL Server (manual)

GCS:

Here you will rely totally on Google. If they index your webpage in 60 days, then good luck. You won't find info which isn't stored, publically like a webpage. Therefore, any content within the login, forget it.

You will also rely on Search Engine Optimization. if you don't optimize your page titles, meta descriptions ect, the search won't be of much use.

Custom SQL Server:

If you put a full text index on your data fields, you can search for your keywords. This is a decent solution, but remember the indexes (otherwise it will be very slow).

I would search for "SQL Server Full text search" for help on this solution.

The benefit here is you have full control and you can access everything.

EDIT:

There are of course many other solutions. I would also suggest looking into Lucene, or some implementations on top of Lucene such as Solr. However all search functionality is usually very difficult and timeconsuming, henceforth my first two suggestions.

In the company I work at we've previously used FAST, and use Apptus today.

EDIT 2:

Today I would advice one solution only: ElasticSearch. It's a great solution; easy to work with; works on all platforms; based on a nice REST api and JSON and is performing very well.

Upvotes: 5

DevGuy
DevGuy

Reputation: 167

If your content is stored in SQL database and you need to search for it inside that DB - then you need some kind of a query builder. There are a few of them on the market. I can remember Aspose Query and EasyQuery but you will find more if google for "query builder asp.net" or something similar.

Upvotes: 0

ggsmartboy
ggsmartboy

Reputation: 454

If you are using the SOL DB Try Enable your own code for Search box in it. For example i'm creating a Video Portal, i'm searching videos by my own Search box by using the following Code,

    <script type="text/javascript">
    $(document).ready(function () {
        SearchText();
    });
    function SearchText() {
        $(".autosuggest").autocomplete({
            source: function (request, response) {
                $.ajax({
                    type: "POST",
                    contentType: "application/json; charset=utf-8",
                    url: "Home.aspx/GetAutoCompleteData",
                    data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
                    dataType: "json",
                    success: function (data) {
                        response(data.d);
                    },
                    error: function (result) {
                        alert("Error");
                    }
                });
            }
        });
    }

    $(".autosuggest").autocomplete({
        source: function (request, response) {
            $.ajax({
                type: "POST",
                contentType: "application/json; charset=utf-8",
                url: "Home.aspx/GetAutoCompleteData",
                data: "{'username':'" + document.getElementById('txtSearch').value + "'}",
                dataType: "json",
                success: function (data) {
                    response(data.d);
                },
                error: function (result) {
                    alert("Error");
                }
            });
        }
    });
</script>

     /// <summary>
    /// To AutoSearch. . .
    /// </summary>
    /// <param name="userName"></param>
    /// <returns></returns>
    public List<string> GetAutoComplete(string userName)
    {
        List<string> lstStr = new List<string>();
        sqlCon = new SqlConnection(strCon);
        sqlCmd=new SqlCommand("select DISTINCT OldFileName from UploadedVideo where OldFileName LIKE '%'+@SearchText+'%'", sqlCon);
        sqlCon.Open();
        sqlCmd.Parameters.AddWithValue("@SearchText",userName);
        SqlDataReader reader=null;
        reader = sqlCmd.ExecuteReader();
        while(reader.Read())
        {
            lstStr.Add(reader["OldFileName"].ToString());
        }
        return lstStr;
    }

I've Created a auto Complete box. The Main thing here is we can use our own code. . .

Upvotes: 1

vikbehal
vikbehal

Reputation: 1524

Use Google Search

*If possible you can use Sharepoint for website development and Search is already there for each website.

Upvotes: 0

Marjan Nikolovski
Marjan Nikolovski

Reputation: 848

Use Lucene (The Apache Lucene project develops open-source search software).

  1. http://lucene.apache.org/

  2. http://ifdefined.com/blog/post/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx

Upvotes: 1

Hammad Akhwand
Hammad Akhwand

Reputation: 799

Your pages are generated from SQL database. I think its safe to assume that the relevant data also lies in the SQL DB rather than the asp templates or the C# code. To search that data you could write multiple queries to the database, based on the contains("search term") function.

You could have a simple search that executes all those queries and also have advanced search where you can provide checkboxes based on which queries to execute to refine the search.

That would make more sense than doing a raw search over generated content, imo.

Upvotes: 1

Darren Wainwright
Darren Wainwright

Reputation: 30727

It's a little difficult knowing which direction you prefer to go on with search functionality, and not knowing what languages you prefer/and are comfortable in using are..

So, how about something simple? and use hosted search?

This site here, for free, will index up to 1000 and you get all sorts of reporting with it too. Looks like you just have to add some simple HTML into your site to get it all working.

you can also re-index on demand and also set up a schedule to do it for you. No need to wait for Google..

The site is Site Level

Upvotes: 0

Related Questions