Sunday, August 17, 2014

Windows Update freezes when you install updates in Windows 8, Windows 7, or Windows Vista

Since last few days my windows 7 did not shutdown and it was waiting to install windows update for ages. I gave that computer almost 12 hours to complete but it didn't work.  For this moment I don't know how I fixed that but I have done following things to fix that. One of those tries will give exact result you want with you windows.


  • Turn of your computer using power button . ( Kill it :D )
  • Start computer in normal mode.
  • Go to windows update.
  • Try to install updated or check for updates again. This will give you  an error message saying that it is installing some other updates. 
  • If that's the case restart your computer again with power button. once windows displays above error message it will stop installing that crappy update.
  • Then go to windows update and click check for updates.
  • If that work install windows updates and get a backup of your system or create a restore point. 
  • That will make sure if something go wrong on next time you'll be safe.

Again I'm really sorry I couldn't get any photos this time and cant exactly say what fix this problem. So follow above steps and let me know your result.


Thanks!

Tuesday, August 5, 2014

Basic Indexing and Searching Example with Apache Lucene.net

Lucene - Previous

1. Add Lucene.net to your application.
  • Copy Lucene.Net project to your solution folder or copy Lucene.Net.dll to your projects 
  • Add reference to Lucene.Net from the project your wish to use lucene as indexing 
  • Build your project.
2. Open writable Lucene database.

 Lucene database is a local file system folder which is the location of encrypted indexfiles generating from lucene.

  • FSDirectory is the class that we are using to create Lucene data folder in file system. This action will create write.lock file in target database path which is the lock file for that database. If you want to release this lock dispose the directory object and delete the write.lock file if its still exists. 

                          FSDirectory objDirectory  =  FSDirectory.GetDirectory(pstrDatabase_path);

  • Create Analyzer object to analyze and remove unnecessary chracters from indexing text. (@, a, :, / etc. )

                          Analyzer Analyzer = new StandardAnalyzer();

  • Create IndexWriter class to index text, html, numbers.

                          IndexWriter Writer = new IndexWriter(objDirectory, Analyzer);

3. Create your first index function with Lucene.


  • From section 2 we have


                FSDirectory objDirectory = FSDirectory.GetDirectory(pstrDatabase_path);
                Analyzer Analyzer = new StandardAnalyzer();
                IndexWriter Writer = new IndexWriter(objDirectory, Analyzer);


  • Create blank Lucene Document. Lucene will store your data as documents. Following code will create blank lucene document in memory. 
                Document doc = new Document();

  • Now we need to add data to this document. Data will be added as fields. Field is a keyvalue pair which include string key and string function. In later sections we may use fields which have custom data types. Following code line will insert string valued field to your lucene documents.


                doc.Add(new Field("FIELD_NAME", "FIELD_VALUE" , Field.Store.YES, 
                                                                                  Field.Index.NOT_ANALYZED));
  • Now we can add this document in to the Lucene writer from following code.
               Writer.AddDocument(doc);
  • Full code of indexing process.
              FSDirectory objDirectory = FSDirectory.GetDirectory(pstrDatabase_path);
              Analyzer Analyzer = new StandardAnalyzer();
              IndexWriter Writer = new IndexWriter(objDirectory, Analyzer);
              Document doc = new Document();
              doc.Add(new Field("FIELD_NAME", "FIELD_VALUE" , Field.Store.YES, 
              Field.Index.NOT_ANALYZED));
              Writer.AddDocument(doc);
              Writer.Commit();
              Writer.Close();

4. Searching an Index.


  • Creating Searcher object. Following code will create searcher object and it will take database path as a parameter.
            Searcher objSearcher = new IndexSearcher("C:\\Lucene_Data");

  • Create QueryParser object.
           QueryParser parser = new QueryParser("Default_Field", new StandardAnalyzer());

  • Create query from QueryParser object.
           Query query_lucene = parser.Parse("FIELD_NAME:FIELD_VALUE" );

  • Searching Lucene database and accessing data of searched documents.

           Hits hits = objSearcher.Search(query_lucene, sort);
           int aprox = (uint)hits.Length();
           for (int i = 0; i < aprox ; i++)
          {
          Document doc = hits.Doc(i);
                  string result = doc.Get("FIELD_NAME ");  
          }
          objSearcher.Close();


  • Complete simple search code.


            Searcher objSearcher = new IndexSearcher("C:\\Lucene_Data");
            QueryParser parser = new QueryParser("Default_Field", new StandardAnalyzer());
            Hits hits = objSearcher.Search(query_lucene, sort);
            int aprox = (uint)hits.Length();

            for (int i = 0; i < aprox ; i++)
           {
        Document doc = hits.Doc(i);
        string result = doc.Get("FIELD_NAME ");
           }

          objSearcher.Close();



If you need any help in other languages PHP, VB.net please comment.


Lucene - Previous





Monday, August 4, 2014

Apache Lucene.net - Introduction


Lucene - Next

What is Lucene.Net? 

Lucene.Net is a high performance Information Retrieval (IR) library, also known as a search engine library. Lucene.Net contains powerful APIs for creating full text indexes and implementing advanced and precise search technologies into your programs. Some people may confuse Lucene.net with a ready to use application like a web search/crawler, or a file search application, but Lucene.Net is not such an application, it's a framework library. Lucene.Net provides a framework for implementing these difficult technologies yourself. Lucene.Net makes no discriminations on what you can index and search, which gives you a lot more power compared to other full text indexing/searching implications; you can index anything that can be represented as text. There are also ways to get Lucene.Net to index HTML, Office documents, PDF files, and much more. Lucene.Net is an API per API port of the original Lucene project, which is written in Java even the unit tests were ported to guarantee the quality. Also, Lucene.Net index is fully compatible with the Lucene index, and both libraries can be used on the same index together with no problems. A number of products have used Lucene and Lucene.Net to build their searches; some well known websites include Wikipedia, CNET, Monster.com, Mayo Clinic, FedEx, and many more. But, it’s not just web sites that have used Lucene; there is also a product that has used Lucene.Net, called Lookout, which is a search tool for Microsoft Outlook that just brought Outlook’s integrated search to look painfully slow and inaccurate. Lucene.Net is currently undergoing incubation at the Apache Software Foundation. Its source code is held in a subversion repository and can be found here. If you need help downloading the source, you can use the free TortoiseSVN, or RapidSVN. The Lucene.Net project always welcomes new contributors. And, remember, there are many ways to contribute to an open source project other than writing code.

Downloading Lucene.Net 

You can find latest versions of Lucene.Net as complied binaries or source files from following URL. http://incubator.apache.org/lucene.net/download.html

Lucene - Next

Sunday, August 3, 2014

Force Image Width and Height Without Stretching

So here is the story. I just wanted to create an  image tag which has the same size of source image size. My problem was whenever the image source size larger than image tag html element image is fitting to borders.
I found the solution after few hours of googling and changing very few CSS lines.

All you have to do is add a style to your img tag like this.

style = "width: auto;height: auto;"

I'll upload the jsfiddle ASAP.

Happy coding fellows....

Linux Distributions For Beginners

1. Linux Mint 17


Linux Mint is the second most popular linux distribution simply because of its user friendliness It comes with loads of software carefully picked by the team, media codecs and drivers. The distro works so well out of the box you will not be spending any time trouble shooting. Mint focuses on what is best for its users and provides what the mainstream linux users demand (most of the time). Linux Mint 15 comes in 2 editions. The Cinnamon edition includes a modern Gnome 3 desktop with a familiar and traditional layout. The MATE edition comes with a Gnome 2 desktop. Compared to the cinnamon edition, the MATE edition is more stable but is outdated and quite boring. After years of development, Cinnamon has become one of the best DEs that are available for linux user who prefer a traditional desktop based on Gnome 3. Cinnamon has plenty of cool little features that are definitely worth checking out and you simply cannot go wrong with mint.
Linux mint is based on Canonical's Ubuntu.

2. Ubuntu 14.04


Ubuntu is the #1 and the most popular distro out there. Even though Linux Mint appeals more to users who prefer a traditional desktop experience, Ubuntu has a rigorous release cycle and tends to have more bleeding edge features implemented in each release. Ubuntu does not come with a load of software and codecs pre installed like Linux Mint. So new users may have trouble playing certain media formats and may require a few command line installations. But due to the excellent community support they can be sorted out within minutes.
Ubuntu comes with its own user interface called "unity". The unity desktop interface has come a long way and comes with tons of unique features that cannot be found on other desktops. But it may be not for everyone as it has a few quirks that some some users may find annoying. Good news is that it is configurable and certain features that you dislike can be disabled. Ubuntu 14.04 adds even more user friendly features to unity and is simply the best distribution for the average linux user.

3. Zorin OS 8


Zorin OS is optimized for users who are transitioning From windows. It looks quite similar to Windows 7 and comes with "zorin look changer" that can make your desktop look similar to older Windows versions and Mac OS X. Zorin OS also offers four premium versions (Ultimate, Business, Multimedia, Gaming) which are available upon donating. There is also a free version that does not come with as much software preinstalled. If you prefer a distro that works and functions similar to windows 7, Zoris OS provides the best out-of-the box experience. (even though other distros can be configured with a bit of effort)

4. Pinguy OS 14.04 LTS


Pinguy OS is an Ubuntu based distribution that comes with A LOT of software preinstalled. It is great for users who want to explore the extensive software that Linux has to offer. It is also very convenient because it includes almost all the software that a user may require. Pinguy OS is a fairly new distro but it is gaining popularity quickly. Pinguy OS includes two Docks by default and the overall look of the desktop leans toward OS X. Pinguy OS 14.04 includes a customized gnome-shell. Pinguy download images are quite huge since it packs a lot of software in it and the OS itself is a bit resource hungry(understandably). If you have a modern computer pinguy should run smoothly but if you have an older and limited PC, you may want to look at a lighter-weight distro.


5. Peppermint OS 4


Peppermint OS a very light distro that comes with LXDE desktop envioronment. LXDE is very simple to use and many will find it to be a straightforward DE. The OS boots up quite fast which makes it ideal for older computers or netbooks. Peppermint OS 4 is based on Lubuntu 13.04. It includes an elegant theme by default and includes media-codecs out of the box. If you require a feature-rich and light-weight distro, peppermint is the way to go.