java - Getting results of a search - lucene 4.4.0 -
i'm experiencing problems on lucene. i'm querying database. far know indexes ok (i checked lukeall-4.4.0). query constructed following:
q = query.split(" "); booleanquery = new booleanquery(); //query[] queryy = new query[5 + 5 * q.length]; query[] queryy = new query[3 + 3*q.length]; //using text queryy[0] = new termquery(new term("designacao", query)); queryy[1] = new termquery(new term("descricao", query)); queryy[2] = new termquery(new term("tag", query)); //using separeted values (int = 3, j = 0; j < q.length; i++, j++) { queryy[i] = new termquery(new term("designacao", q[j])); queryy[++i] = new termquery(new term("descricao", q[j])); queryy[++i] = new termquery(new term("tag", q[j])); } (int = 0; < queryy.length; i++) { booleanquery.add(queryy[i], booleanclause.occur.must); }
the query ok. searching "not or" query (a booleanquery) going following:
+designacao:not or +descricao:not or +tag:not or +designacao:not +descricao:not +tag:not +designacao:or +descricao:or +tag:or
i'm using simpleanalyser, words not , or not removed. problem can't hits. can have hits if make search lukeall-4.4.0 not code. search method following one:
indexreader reader = indexreader.open(directory1); topscoredoccollector collector = topscoredoccollector.create(50, true); searcher = new indexsearcher(reader); searcher.search(booleanquery, collector); hits = collector.topdocs().scoredocs; int total = collector.gettotalhits(); displayresults();
is there wrong in collecting data or something??
kind regards
piece of cake. problem in construction of query:
for (int = 0; < queryy.length; i++) { booleanquery.add(queryy[i], booleanclause.occur.must); }
the booleanclause.occur.must
means has exist. thus, terms adding booleanquery must exist (term1 , term2 , term3). correct is:
booleanquery.add(queryy[i], booleanclause.occur.should);
this way can has exist 1 of terms have added (term1 or term2 or term3).
kind regards
Comments
Post a Comment