Showing posts with label Search. Show all posts
Showing posts with label Search. Show all posts

Android App Development: Implementing Search activities

Most Android phones have a search button. this button is used to search contacts,applications or anything on the phone. We can make use of the search functionality in our apps.

In this post we’re going to see how to implement search functionality to search for entries stored in a databaseand display them in a ListView.

our database has two tables: Countries and Names:

public class DBHelper extends SQLiteOpenHelper {public DBHelper(Context context) {super(context, "DemoDB", null, 1);}@Overridepublic void onCreate(SQLiteDatabase db) {StringBuilder builder=new StringBuilder();// countries tablebuilder.append("CREATE TABLE Countries ");builder.append("(_id INTEGER PRIMARY KEY AUTOINCREMENT,");builder.append("NAME TEXT) ");db.execSQL(builder.toString());// Names table// Virtual table for full text searchbuilder.setLength(0);builder.append("CREATE VIRTUAL TABLE NAMES USING FTS3");builder.append("(");builder.append("name TEXT) ");db.execSQL(builder.toString());builder=new StringBuilder();//dummy dataInsertData(db);} void InsertData(SQLiteDatabase db) { ContentValues cv=new ContentValues();cv.put("NAME","USA");db.insert("Countries", "NAME", cv);cv.put("NAME","UK");db.insert("Countries", "NAME", cv);cv.put("NAME","Spain");db.insert("Countries", "NAME", cv);cv.put("NAME","ITALY");db.insert("Countries", "NAME", cv);cv.put("NAME","Germany");db.insert("Countries", "NAME", cv); cv=new ContentValues();cv.put("name","John");db.insert("NAMES", "name", cv);cv.put("name","Jack");db.insert("NAMES", "name", cv);cv.put("name","Ann");db.insert("NAMES", "name", cv);cv.put("name","Adam");db.insert("NAMES", "name", cv);cv.put("name","Sarah");db.insert("NAMES", "name", cv); }@Overridepublic void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {// TODO Auto-generated method stub}}

notice that the Names table is a VIRTUAL table. we created it as virtual to make use of Full Text Search (FTS3) feature in SQLite. this feature makes queries faster than that in regular tables.

then we add two functions to retrieve all rows from both tables:

/** * Return all countries * @return */public ArrayListgetCountries(){ArrayList countries=new ArrayList();SQLiteDatabase db=this.getReadableDatabase();Cursor c=db.rawQuery("select * from Countries", null);while(c.moveToNext()){String country=c.getString(1);countries.add(country);}c.close();return countries;}/** * Return all names * @return */public ArrayListgetNames(){ArrayList names=new ArrayList();Cursor c=this.getReadableDatabase().rawQuery("select * FROM Names", null);while(c.moveToNext()){String name=c.getString(0);names.add(name);}c.close();return names;}

and another two functions to retrieve data based on a search string:

/** * Return all countries based on a search string * @return */public ArrayListgetCountriesSearch(String query){ArrayList countries=new ArrayList();SQLiteDatabase db=this.getReadableDatabase();Cursor c=db.rawQuery("select * from Countries where NAME LIKE '%"+query+"%'", null);while(c.moveToNext()){String country=c.getString(1);countries.add(country);}c.close();return countries;}/** * Return all names based on a search string * we use the MATCH keyword to make use of the full text search * @return */public ArrayListgetNamesSearch(String query){ArrayList names=new ArrayList();Cursor c=this.getReadableDatabase().rawQuery("select * FROM Names WHERE name MATCH '"+query+"'", null);while(c.moveToNext()){String name=c.getString(0);names.add(name);}c.close();return names;}

then we will create our activity that has a list view like this:


we load data from database like this:

public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView)findViewById(R.id.list); DBHelper helper=new DBHelper(this); ArrayList items=helper.getNames(); ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,items); list.setAdapter(adapter);}

In order to handle the search dialog ourselves we need to create a xml file with search configurations such as the search dialog title, voice search capabilities, content provider for auto complete and so on. we create a file with the name searchable.xml in res/xmldirectory:

the android:hint attribute denotes a string that acts as a water mark on the search text box.
then we need to add an Intent Filter in out app’s AndroidManifest.xml file to our activity to handle the search dialog:

when you press the search button, type some text and click on search the activit’s onSearchRequested() function is called, then an Intent with the action Intent.ACTION_SEARCH is created and you activity is re-created with this intent.
the search intent has you search string as a string extra with the name SearchManager.QUERY. also it can carry a bundle of other extras with the name SearchManager.APP_DATA.

not all Android devices have a search button, so we can start the search dialog manually by calling the activity’s onSearchRequested() from a button or a menu item:

@Override public boolean onCreateOptionsMenu(Menu menu) { menu.add("Search").setOnMenuItemClickListener(new OnMenuItemClickListener() {@Overridepublic boolean onMenuItemClick(MenuItem item) { //launch the search dialogonSearchRequested();return true;}}); return true; }

we can pass some extra data as a bundle with our search dialog or an initial search string by overriding the activity’s onSearchRequested():

@Override public boolean onSearchRequested() { Bundle bundle=new Bundle();bundle.putString("extra", "exttra info");// search initial querystartSearch("Country", false, bundle, false);return true; }

we said before that the search query is passed as a String extra when our activity is re-created. so we can handle the searcgh string in our onCreate() like this:

@Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.main); list=(ListView)findViewById(R.id.list); DBHelper helper=new DBHelper(this); Intent intent=getIntent(); // if the activity is created from search if(intent.getAction().equals(Intent.ACTION_SEARCH)){ // get search query String query=intent.getStringExtra(SearchManager.QUERY); ArrayList items=helper.getNamesSearch(query); //get extras, just for demonstration Bundle bundle=intent.getBundleExtra(SearchManager.APP_DATA); String info=bundle.getString("extra"); Log.v("extra", info); //bind the list ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,items); list.setAdapter(adapter); } //activity created normally else{ ArrayList items=helper.getNames(); ArrayAdapter adapter=new ArrayAdapter(this, android.R.layout.simple_list_item_1,items); list.setAdapter(adapter); } helper.close(); }

we just extract the search string and any other extras and perform our search logic based on the search string.
and that’s was all about implementing search, stay tuned for another Android tutorial

More aboutAndroid App Development: Implementing Search activities

Google Launched Official Search Blog

Google In the past published information about search on the Official Google Blog (more than 400 posts about search and more than 50 weekly wrap-ups), and webmaster-oriented posts on the Webmaster Central Blog (more than 300 posts). But now it has launched an exclusive search blog for latest updates about the Google search technology. You can get all the search updates in this new official Google blog.


search blog Google Launched Official Search Blog


See what Google saying about this new launch…



The thirst for knowledge is as old as humanity. It’s only in the past decade that the Internet has made knowledge ubiquitous, and we want to help you find the answers you’re looking for, whether it’s the best price on a new microwave, where to find a great bike ride—or even information about the Internet itself.


Generally, we help you answer questions by refining our algorithms, but today we’re taking a slightly different approach: we’re starting a blog — this blog — “Inside Search.” Here you’ll find regular updates on our algorithms and features, as well as stories from the people who work to improve Google every day.


In the past we’ve published information about search on the Official Google Blog (more than 400 posts about search and more than 50 weekly wrap-ups), and webmaster-oriented posts on the Webmaster Central Blog (more than 300 posts). We also operate a help center for search and another for webmasters. That’s not to mention the search help forums which have more than 50,000 discussions, and the webmaster central help forums with more than 90,000. Combine this with YouTube channels and search conferences, and it’s safe to say we talk a lot about search.


Even with all these channels, we still felt we were missing something. We didn’t want to flood the Official Google Blog with smaller stories and announcements, and the Webmaster Central Blog is really meant for, well, webmasters. We started our series “This week in search” to provide a way to share information about some of the smaller updates we’re making, but we got feedback that people wanted their search news and information as it happens, not just weekly. So, we’re starting Inside Search as a place where you can find regular updates on the intricacies of search and our team. We have more engineers working on search than any other product, and each one of us has stories to tell.


So this is all about “Google Launched Official Search Blog“, drop your comments on the same in the below section…

Share This :FacebookEmailPrintStumbleUpon
More aboutGoogle Launched Official Search Blog

Sprint’s cool commercial for Nexus S 4G


Sprint's Cats commercial for Nexus S 4G


Verizon and Google announced 4G version of Nexus S for it’s LTE network which arrived on May 8th After a few weeks of launching Verizon just started a whole advertising campaign for Nexus S 4G. The 31 seconds features Cats using Google voice search and having Pure Google experience including filling the Internet with more cats. Let’s watch below the commercial Nexus S 4G Cats:
YouTube Preview Image


Wasn’t the Ad cool? In courtesy of YouTube the commercial has now over 85000 views and rapidly counting more. We guess Verizon to have a  successful campaign. Sprint’s Nexus S 4G also available for $150 in Best Buy.

More aboutSprint’s cool commercial for Nexus S 4G

Search Any Files Uploaded On The Net Easily And fast



 


If are searching for the sites which allow you to download free movies, videos, mp3, TV, series, games and text files, then General-Files is the great website. You can search for all these stuffs since it is a downloadable search engine as well. General-Files is one of the popular file sharing site.


Its major feature is its search engines which allow you to search for the required files online. By using this site, you can search for the files containing in other file sharing site like RapidShare, 4Shared, Fileserve, etc as well. Its search features is more advanced where you can search files by filtering file size and types.


You can increase your working efficiency by using General-Files. As other site, it allow you to upload your any files and share it to your friends.


You can also register new account at General-Files and start sharing videos, mp3, TV, series, games and text files freely. Within 2 steps that is search and download you can enjoy this site. With the motto "Files for Everyone" its going on very well and being popular day by day. Also, you can download videos for free!


This site is very helpful since you can search any file uploaded by using the popular file uploading sites on the net. In short we can say it is the general search engine for any files upload on the net.

More aboutSearch Any Files Uploaded On The Net Easily And fast

The Google Click Through Rate (CTR) On Top 10 Search Results

Have you even noticed the increase in traffic when your website, blog’s url lies on first page of Google search? Although this is not an easy task to get yourself on top searches as it needs a time to make that much worth against your website, blog. or likely you have much outstanding article with best keyword may gives you a chance to reside on first page search.


What Is The Difference Getting On First Page of Google Search?


I was just reading the content with an infographic image at Labnol and found it help for many webmasters an SEO’s. Optify [PDF] had made a strong research and reveled that 36.4% of users like to click on your website/blog if it lies on number one page of Google search, and unluckily pages which resides on page number two of Google search, the click through rate (CTR) lowers by 12.5%, which is really too low. The report also verifies the average click through rate on being page number one is 8.9% which lowers down to 1.5% for sites on page number two.


SEW-CTR-screenshot


The infographic made by Search Engine Watch who have transformed all the CTR data into a useful infographic [PDF] to help you understand more better. If you are a webmaster or SEO in an organization this might help you giving them a boost to increase traffic and revenue.

More aboutThe Google Click Through Rate (CTR) On Top 10 Search Results