Tuesday, June 2, 2009

Solr/Lucene .

I am trying to add up what I learned so far on the Solr.

Lucene : Is the search engine

Solr : The Search Server.

Solr / Lucene Terms.

Facet --- The data that have to be breakdown. example: manufacturer
FacetField -- This will contain the facet data
SolrDocument -- This will contain one solr search data.
setFacetMinCount -- This will limit returning search data with the minimum count of hit.
A sample Query using SolrJ
query.addFacetField("manu"); query.setFacetMinCount(1); query.setIncludeScore(true); List facetFieldList=qr.getFacetFields(); for(FacetField facetField: facetFieldList){ System.out.println(facetField.toString() +"Manufactures"); } And it returns ----------------- [manu:[dell (5), inc (5), corp (1), sharp (1), sonic (1), view (1), viewson (1), vizo (1)]] Notice here it will return only manufactures with facet count 1 and above.
Solr Price Range:
Querying price range need little special skill in solr, I am still exploring different option of querying. The search querys are case sensitive, if you put 'To' instead of 'TO' solr will throw invalid syntax error.
query.addFacetQuery("price:[* TO 500]"); query.addFacetQuery("price:[500 TO 1000]"); query.addFacetQuery("price:[1000 TO *]"); HashMap priceRangeMap = (HashMap) qr.getFacetQuery(); Iterator priceRageIter=priceRangeMap.entrySet().iterator(); System.out.println(qr.getFacetQuery().toString()); while(priceRageIter.hasNext()){ Map.Entry pairs = (Map.Entry)priceRageIter.next(); System.out.println(pairs.getKey() + " -- found -- " + pairs.getValue()); } And it will return ---------------------- {price:[* TO 500]=1, price:[500 TO 1000]=2, price:[1000 TO *]=6} price:[* TO 500] -- found -- 1 price:[500 TO 1000] -- found -- 2 price:[1000 TO *] -- found -- 6

0 Comments: