views:

141

answers:

1

Hello, I am having problem with lucene boosting, Iam trying to boost a particular document which matches with the (firstname)field specified I have posted the part of the codeenter code hereprivate static Document

createDoc(String lucDescription,String primaryk,String specialString){
  Document doc = new Document();
  doc.add(new Field("lucDescription",lucDescription, Field.Store.NO, Field.Index.TOKENIZED));
  doc.add(new Field("primarykey",primaryk,Field.Store.YES,Field.Index.NO));
  doc.add(new Field("specialDescription",specialString, Field.Store.NO, Field.Index.UN_TOKENIZED));
  doc.setBoost ((float)(0.00001));
  if (specialString.equals("chris"))
  doc.setBoost ((float)(100000.1));
  return doc;

 }

why is this not working?enter code here

public static String dbSearch(String searchString){
  List<String> pkList = new ArrayList<String>();
  String conCat="(";
  try{
   String querystr = searchString;

   Query query = new QueryParser("lucDescription", new StandardAnalyzer()).parse(querystr);  
   IndexSearcher searchIndex = new IndexSearcher("/home/athreya/docsIndexFile");
   // Index of the User table--> /home/araghu/aditya/indexFile.
   Hits hits = searchIndex.search(query);
   System.out.println("Found " + hits.length() + " hits.");
   for(int iterator=0;iterator<hits.length();iterator++) {
    String primKey=hits.doc(iterator).get("primarykey");
    System.out.println(primKey);
    pkList.add(primKey);
   }
   searchIndex.close();

Thank you in advance Athreya

A: 

Hard to say what could be wrong just looking at the code, couple of things to try:

  1. open the index with Luke and see the score for the document (containing "chris")
  2. Unsure if you are bypassing one or the other setboost calls.

    if (specialString.equals("chris")) doc.setBoost ((float)(100000.1)); else doc.setBoost ((float)(0.00001));

Mikos
Ok, thanks for the reply
Athreya
if (specialString.equals("chris")) doc.setBoost ((float)(100000.1)); else doc.setBoost ((float)(0.00001));hereI am trying here to nullify the boost if the doc is not found and maximise it if found so that the score for the doc if found will be high
Athreya
ok, but your code above seems counterintuitive, perhaps put the un-boost in an else statement. Also look at the index using Luke, that would tell you a lot more about scoring.
Mikos