Creating a search functionality in ASP.NET - 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?
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.
Microsoft Index Server: http://www.c-sharpcorner.com/UploadFile/sushil%20saini/UsingIndexServer11262005045132AM/UsingIndexServer.aspx
or ...
Google Custom Search: http://www.google.com/coop/cse/
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.
Use Lucene (The Apache Lucene project develops open-source search software).
http://lucene.apache.org/
http://ifdefined.com/blog/post/Full-Text-Search-in-ASPNET-using-LuceneNET.aspx
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. . .
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
Use Google Search
*If possible you can use Sharepoint for website development and Search is already there for each website.
Here you can found a best tutorial.
http://www.codeproject.com/Articles/42454/Implement-Search-Functionality-into-your-ASP-NET-M
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.
Related
How to do pattern searching in fire base real time DB [duplicate]
I am using firebase for data storage. The data structure is like this: products:{ product1:{ name:"chocolate", } product2:{ name:"chochocho", } } I want to perform an auto complete operation for this data, and normally i write the query like this: "select name from PRODUCTS where productname LIKE '%" + keyword + "%'"; So, for my situation, for example, if user types "cho", i need to bring both "chocolate" and "chochocho" as result. I thought about bringing all data under "products" block, and then do the query at the client, but this may need a lot of memory for a big database. So, how can i perform sql LIKE operation? Thanks
Update: With the release of Cloud Functions for Firebase, there's another elegant way to do this as well by linking Firebase to Algolia via Functions. The tradeoff here is that the Functions/Algolia is pretty much zero maintenance, but probably at increased cost over roll-your-own in Node. There are no content searches in Firebase at present. Many of the more common search scenarios, such as searching by attribute will be baked into Firebase as the API continues to expand. In the meantime, it's certainly possible to grow your own. However, searching is a vast topic (think creating a real-time data store vast), greatly underestimated, and a critical feature of your application--not one you want to ad hoc or even depend on someone like Firebase to provide on your behalf. So it's typically simpler to employ a scalable third party tool to handle indexing, searching, tag/pattern matching, fuzzy logic, weighted rankings, et al. The Firebase blog features a blog post on indexing with ElasticSearch which outlines a straightforward approach to integrating a quick, but extremely powerful, search engine into your Firebase backend. Essentially, it's done in two steps. Monitor the data and index it: var Firebase = require('firebase'); var ElasticClient = require('elasticsearchclient') // initialize our ElasticSearch API var client = new ElasticClient({ host: 'localhost', port: 9200 }); // listen for changes to Firebase data var fb = new Firebase('<INSTANCE>.firebaseio.com/widgets'); fb.on('child_added', createOrUpdateIndex); fb.on('child_changed', createOrUpdateIndex); fb.on('child_removed', removeIndex); function createOrUpdateIndex(snap) { client.index(this.index, this.type, snap.val(), snap.name()) .on('data', function(data) { console.log('indexed ', snap.name()); }) .on('error', function(err) { /* handle errors */ }); } function removeIndex(snap) { client.deleteDocument(this.index, this.type, snap.name(), function(error, data) { if( error ) console.error('failed to delete', snap.name(), error); else console.log('deleted', snap.name()); }); } Query the index when you want to do a search: <script src="elastic.min.js"></script> <script src="elastic-jquery-client.min.js"></script> <script> ejs.client = ejs.jQueryClient('http://localhost:9200'); client.search({ index: 'firebase', type: 'widget', body: ejs.Request().query(ejs.MatchQuery('title', 'foo')) }, function (error, response) { // handle response }); </script> There's an example, and a third party lib to simplify integration, here.
I believe you can do : admin .database() .ref('/vals') .orderByChild('name') .startAt('cho') .endAt("cho\uf8ff") .once('value') .then(c => res.send(c.val())); this will find vals whose name are starting with cho. source
The elastic search solution basically binds to add set del and offers a get by wich you can accomplish text searches. It then saves the contents in mongodb. While I love and reccomand elastic search for the maturity of the project, the same can be done without another server, using only the firebase database. That's what I mean: (https://github.com/metaschema/oxyzen) for the indexing part basically the function: JSON stringifies a document. removes all the property names and JSON to leave only the data (regex). removes all xml tags (therefore also html) and attributes (remember old guidance, "data should not be in xml attributes") to leave only the pure text if xml or html was present. removes all special chars and substitute with space (regex) substitutes all instances of multiple spaces with one space (regex) splits to spaces and cycles: for each word adds refs to the document in some index structure in your db tha basically contains childs named with words with childs named with an escaped version of "ref/inthedatabase/dockey" then inserts the document as a normal firebase application would do in the oxyzen implementation, subsequent updates of the document ACTUALLY reads the index and updates it, removing the words that don't match anymore, and adding the new ones. subsequent searches of words can directly find documents in the words child. multiple words searches are implemented using hits
SQL"LIKE" operation on firebase is possible let node = await db.ref('yourPath').orderByChild('yourKey').startAt('!').endAt('SUBSTRING\uf8ff').once('value');
This query work for me, it look like the below statement in MySQL select * from StoreAds where University Like %ps%; query = database.getReference().child("StoreAds").orderByChild("University").startAt("ps").endAt("\uf8ff");
Delete multiple records in an Azure Table
I have a mobile app written using Apache Cordova. I am using Azure Mobile Apps to store some data. I created Easy Tables and 1 Easy API. The purpose of the API is to perform delete / update more than 1 record. Below is the implementation of the API. exports.post = function (request, response){ var mssql = request.service.mssql; var sql = "delete from cust where deptno in ( ? )"; mssql.query(sql, [request.parameters],{ success : function(result){ response.send(statusCodes.OK, result); }, error: function(err) { response.send(statusCodes.BAD_REQUEST, { message: err}); } }); } Is there any other way to implement it ? The del() method on table object on takes id to delete and I didn't find any other approach to delete multiple rows in the table. I am having difficulty to test the implementation as the changes in the API code is taking 2-3 hours on average to get deployed. I change the code through Azure website and when I run it, the old code is hit and not the latest changes. Is there any limitation based on the plans we choose? Update The updated code worked. var sql = "delete from trollsconfig where id in (" + request.body.id + ")"; mssql.query(sql, [request.parameters],{ success : function(result){ response.send(statusCodes.OK, result); }, error: function(err) { response.send(statusCodes.BAD_REQUEST, { message: err}); } });
Let me cover the last one first. You can always restart your service to use the latest code. The code is probably there but the Easy API change is not noticing it. Once your site "times out" and goes to sleep, the code gets reloaded as normal. Logging onto the Azure Portal, selecting your site and clicking Restart should solve the problem. As to the first problem - there are a variety of ways to implement deletion, but you've pretty much got a good implementation there. I've not run it to test it, but it seems reasonable. What don't you like about it?
Override the method of packing HTTP form-urlencoded parameters in Meteor HTTP call
I'm using Meteor to consume a remote API. One of the endpoints of this API requires an (ordered) array of credentials, so the data would look like { "country": "de", "credentials": ["admin", "password"], "whatever": "whatever" } When I provide this plain-object as the value to param property of HTTP.post like this HTTP.post('https://api.whatever.org/whatever', { headers: { "Authorization": "Basic ".concat(...) }, params: { "country": "de", "credentials": ["admin", "password"], "whatever": "whatever" } }); then the parameters are packed this way: country=de credentials=admin,password whatever=whatever but they should be packed this way: country=de credentials=admin credentials=password whatever=whatever I tried using a Content-Type header but it didn't help. I tried using content and data instead of params with different outcomes and then ended concatenating all the values into a query string an putting it into content property. But this isn't really a nice piece of code and surely not one that is easy to maintain. I've read docs but haven't found anything that would help. Where should I look for the information regarding this topic? Is there a better way to override the way HTTP.post (or, in general, HTTP.call) computes the body of the query to send?
Where should I look for the information regarding this topic? In the source code. I know nothing about Meteor, but I’m looking into its source code and I see no public hook which could help you. Of course, you can replace URL._encodeParams with your own function, but that is less maintainable than submitting the encoded params as raw data.
Making autocomplete search faster in asp.net
I have implemented an auto-complete search on my website using ajax autocomplete control.It uses web service which returns results from database. I have a stored procedure which searches for all text values in all columns of all tables for this purpose. The problem here is results taking long to show up in autcomplete control. I have also applied indexing on the most frequently searched table columns, but that to didn't help much. Can this be because of the load on the server, since the server is not a dedicated one. If not how can I fetch the results faster?
You can always optimise the queries to load data faster and use server side caching to cache the data. Also on UI I would recommend you to use jQuery autocomplete plugin <script> $(function() { var availableTags = [ "ActionScript", "AppleScript" ]; $( "#tags" ).autocomplete({ source: availableTags }); }); </script>
Debugging google.maps.FusionTablesLayer
Is there any failureCallback when creating a FusionTablesLayer? Is there a way to know if there is a problem with your query? Or how many rows were loaded from the query? var layer = new google.maps.FusionTablesLayer({ query: { select: 'address', from: '198945', where: 'ridership > 5000' } });
The short answer to both your questions is no. I've relied on the undocumented Fusion Table JSONP support to both easily test queries without worrying about GMap stuff and as well to retrieve the row count from a particular query. Robin Kraft documented this JSONP approach using jQuery at this blog: http://www.reddmetrics.com/2011/08/10/fusion-tables-javascript-query-maps.html As well there has been discussion of this on the old FT API Google Group. Eric