11

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?

1
  • You can do it using custom google search, existing commercial modules, using the sql indexing, up to make your custom indexing. Commented Oct 27, 2012 at 7:48

9 Answers 9

5
+50

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.

Sign up to request clarification or add additional context in comments.

Comments

2

Microsoft Index Server: http://www.c-sharpcorner.com/UploadFile/sushil%20saini/UsingIndexServer11262005045132AM/UsingIndexServer.aspx

or ...

Google Custom Search: http://www.google.com/coop/cse/

4 Comments

How about if the website is hosted at an ISP on a shared server? Whats the best alternative?
In that case, using the Google Custom Search is your best bet.
I'm surprised you didn't suggest to write a search page using ASP.NET?
My first suggestion above is to use ASP.NET and Microsoft Indexing. but getting that done on a shared ISP server might be more hassle than it is worth.
1

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.

1 Comment

This approach, while technically feasible, tends to produce poor end results because people do not think in such concrete terms. They enter a search term and they expect variants and such to be considered. What you get is a search that people are constantly grousing about. The complaints run like "I searched for 'hiking' but you don't show any pages with 'hike' in it"--all those little variants that contains just doesn't hit. In the end, you are better off using either a full text search or a custom google search, as other commentators have said.
1

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

Comments

1

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. . .

Comments

0

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

1 Comment

Thanks for the alternative suggestion to search. I will hv to venture and take a look.
0

Use Google Search

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

Comments

0

Here you can found a best tutorial.

http://www.codeproject.com/Articles/42454/Implement-Search-Functionality-into-your-ASP-NET-M

Comments

0

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.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.