/* Copyright: * transaxtions llc * 4302 Denker Dr, Pleasanton, CA 94588, USA * * License: * Please see License Agreement. Contact transaxtions llc for more info. * * Author: * Nagendra Nagarajayya * * Ver: * 1.0 * * Description: * Needs 3-4 arguments. * First argument, specifies the index, * second the field, * third, the search terms, * fourth optional, field name to output. * * Comments: * 2010/12/27 - First release */ package com.transaxtions.search.examples; import org.apache.lucene.analysis.standard.StandardAnalyzer; import org.apache.lucene.queryParser.QueryParser; import org.apache.lucene.search.IndexSearcher; import org.apache.lucene.search.Query; import com.transaxtions.search.rankingalgorithm.*; /** * Example code showing RankingAlgorithm usage. Very easy to uses, similar to * Lucene API. Needs access to a Lucene index to work. *
 * {@code
 * args[0] is a lucene index path
 * args[1] is the field to search on
 * args[2] are the search terms
 * args[3] is the field to show in the results
 * 
 * Example: 
 * 	java com.transaxtions.search.example.Example "/lucene/perl/index" text "extracting strings from an array" id
 * }
 * 
* * @author Nagendra Nagarajayya * * @see RankingQuery * @see RankingHits * @see RankingScore * */ public class Example { static public void main(String args[]) { String index = args[0]; // lucene index path String field = args[1]; // field to search String searchterms = args[2]; // search terms String title = null; // field to output, default title System.out.println("args len=" + args.length); if (args.length > 3) { title = args[3]; } if (title == null) { title = "title"; } try { RankingQuery rq = new RankingQuery(); IndexSearcher is = new IndexSearcher(index); StandardAnalyzer analyzer = new StandardAnalyzer(); QueryParser parser = new QueryParser(field, analyzer); Query query = parser.parse(searchterms); RankingHits rh = rq.search(query, is); System.out.println("num hits=" + rh.getNumHits() + "--no docs=" + is.maxDoc()); for (int i=0; i