lucene-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Priyanka Tufchi <priyanka.tuf...@launchship.com>
Subject Need Help In code
Date Thu, 30 Jan 2014 07:20:16 GMT
Hello

This is the Sample Code Of BlockJoinQuery( we tried  .
Issues:
1)Dont know how to get hits and score from it
2) This code is not giving output.

I have attached the code for easy view


StandardAnalyzer analyzer = new StandardAnalyzer(Version.LUCENE_41);
// 1. create the index
Directory index = new RAMDirectory();
IndexWriterConfig config = new IndexWriterConfig(Version.LUCENE_41,
analyzer);

IndexWriter w = new IndexWriter(index, config);
List<Document> documents=new ArrayList<Document>();
documents.add(createProductItem("red", "s", "999"));
documents.add(createProductItem("red", "m", "1000"));
documents.add(createProductItem("red", "l", "2000"));
documents.add(createProduct("...Polo Shirt", ".....Made Of 100% cotton"));
w.addDocuments(documents);
documents.clear();
documents.add(createProductItem("light blue", "s", "1000"));
documents.add(createProductItem("blue", "s", "1900"));
documents.add(createProductItem("dark blue", "s", "1999"));
documents.add(createProductItem("light blue", "m", "2000"));
documents.add(createProductItem("blue", "m", "2090"));
documents.add(createProductItem("dark blue", "m", "2099"));
documents.add(createProduct(".....white color", "...stripe pattern"));
w.addDocuments(documents);
IndexReader indexreader=DirectoryReader.open(w, false);
IndexSearcher indexsearcher=new IndexSearcher(indexreader);
Query parentQuery= new TermQuery(new Term("doctype", "product"));
Filter parentfilter=new CachingWrapperFilter(new
QueryWrapperFilter(parentQuery));
Query childQuery=new TermQuery(new Term("size","m"));
ScoreMode scoremode=ScoreMode.Max;
//String Query="blue AND l";
BooleanQuery mainQuery=new BooleanQuery();
//need to check this parameters
mainQuery.add(childQuery,Occur.MUST);
//mainQuery.add(query, occur);
ToParentBlockJoinQuery productitemQuery=new
ToParentBlockJoinQuery(mainQuery, parentfilter,
scoremode);
ToParentBlockJoinCollector c = new ToParentBlockJoinCollector(
   Sort.RELEVANCE, // sort
   10,             // numHits
   true,           // trackScores
   false           // trackMaxScore
   );

indexsearcher.search(productitemQuery,c);


Mime
View raw message