Reputation: 2023
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
Reputation: 9966
The 2 best solutions:
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
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
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
Reputation: 632
Here you can found a best tutorial.
http://www.codeproject.com/Articles/42454/Implement-Search-Functionality-into-your-ASP-NET-M
Upvotes: 0
Reputation: 1524
Use Google Search
*If possible you can use Sharepoint for website development and Search is already there for each website.
Upvotes: 0
Reputation: 848
Use Lucene (The Apache Lucene project develops open-source search software).
Upvotes: 1
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
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
Reputation: 16675
Microsoft Index Server: http://www.c-sharpcorner.com/UploadFile/sushil%20saini/UsingIndexServer11262005045132AM/UsingIndexServer.aspx
or ...
Google Custom Search: http://www.google.com/coop/cse/
Upvotes: 2