About Me

Android, HTML5 and BlackBerry apps developers. Proactive towards new technologies. Reading books, playing chess are my hobbies.

Tuesday, December 9, 2014

Lucene Search API : Lucene Search implementation - Part 2

For understanding what is Lucene Index and creating Lucene Indexes, please take a look into my previous article here


Searching on the Index file:

Searching is the process of looking for words in the index and finding the documents that contain those words.
The following are the fundamental Lucene classes for searching a given text: Searcher, Term.

Searcher : Searcher is an abstract base class that has various search methods. The Search method returns an ordered collection of documents ranked by computed scores. Lucene calculates a score for each of the documents that match a given query.

IndexSearcher is most commonly used subclass that allows searching indices stored in a given directory. IndexSearcher is thread-safe, a single instance can be used by multiple threads concurrently.

SearcherFactory is a factory class used to customize the search results.

Term : Term is the most fundamental unit for searching. It's composed of two elements: the text of the word and the name of the field(column name) in which the text occurs.

Query : Query is an abstract base class for queries. Searching for a specified word or phrase involves wrapping them in a term, adding the terms to a query object, and passing this query object to IndexSearcher's search method.

Lucene comes with various types of concrete query implementations, such as TermQuery, BooleanQuery, PhraseQuery, PrefixQuery, RangeQuery, MultiTermQuery, FilteredQuery, SpanQuery, etc.

Displaying Results :

IndexSearcher returns an array of references to ranked search results, such as documents. Primary classes involved in retrieving the search results are ScoreDoc and TopDocs.

ScoreDoc  A simple pointer to a document contained in the search results. This encapsulates the position of a document in
the index and the score(number of matches) computed by Lucene.

TopDocs  Encapsulates the total number of search results and an array of ScoreDoc

Charles proxy - configuration behind firewall

Charles is an HTTP proxy / HTTP monitor / Reverse Proxy that enables a developer to view all of the HTTP and SSL / HTTPS traffic between their machine and the Internet. This includes requests, responses and the HTTP headers (which contain the cookies and caching information). (Source )

You can download the Charles proxy from charles

If your machine is not under any firewall then configuring Charles is pretty straightforward and is clearly explained here

However if your machine is under firewall then the following changes are required on your machine.

Steps to do this on Windows 7 machine :


  1. Control Panel ---> Network and Internet ---> Network and Sharing Center
  2. Click on Windows Firewall (located at the bottom left)
  3. Advanced Settings
  4. Click on Inbound Rules (located at top left)
  5. Click on New Rule (located at top right)
  6. Rule Type --> Program --> Next
  7. Program ---> Browse to the Charles.exe installation path --> Next
  8. Action ---> Allow the connection ---> Next
  9. Profile ---> Select All the options ---> Next
  10. Name ---> Assign any name and Click Finish.
Now in the Under Windows Firewall window --> Click "Allow a program or feature.." to verify the rule that is created. If the rule is successfully created it should appear here and you good to play with Charles Proxy.

Happy Proxying !!