Michael Wyraz created LUCENE-4049:
-------------------------------------
Summary: PrefixQuery (or it's superclass MultiTermQuery) ignores
index time boosts
Key: LUCENE-4049
URL: https://issues.apache.org/jira/browse/LUCENE-4049
Project: Lucene - Java
Issue Type: Bug
Components: core/search
Affects Versions: 3.6, 3.5
Environment: Java
Reporter: Michael Wyraz
It is possible to set boost to fields or documents during indexing, so certain
documents can be boostes over others. This works well with TermQuery or
FuzzyQuery but not with PrefixQuery which ignores the individual values.
Test Code below:
import java.io.IOException;
import org.apache.lucene.analysis.standard.StandardAnalyzer;
import org.apache.lucene.document.Document;
import org.apache.lucene.document.Field;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.index.IndexWriter;
import org.apache.lucene.index.IndexWriterConfig;
import org.apache.lucene.index.Term;
import org.apache.lucene.search.IndexSearcher;
import org.apache.lucene.search.PrefixQuery;
import org.apache.lucene.search.Query;
import org.apache.lucene.search.ScoreDoc;
import org.apache.lucene.search.TopScoreDocCollector;
import org.apache.lucene.store.Directory;
import org.apache.lucene.store.RAMDirectory;
import org.apache.lucene.util.Version;
import com.evermind.tools.calendar.StopWatch;
public class LuceneTest
{
public static void main(String[] args) throws Exception
{
Directory index=new RAMDirectory();
StandardAnalyzer analyzer=new StandardAnalyzer(Version.LUCENE_35);
IndexWriterConfig config=new IndexWriterConfig(Version.LUCENE_35,
analyzer);
IndexWriter w = new IndexWriter(index, config);
addDoc(w, "Hello 1",1);
addDoc(w, "Hello 2",2);
addDoc(w, "Hello 3",1);
w.close();
StopWatch.stop();
IndexReader reader = IndexReader.open(index);
IndexSearcher searcher = new IndexSearcher(reader);
// Query q = new TermQuery(new Term("f1","hello"));
Query q = new PrefixQuery(new Term("f1","hello"));
TopScoreDocCollector collector = TopScoreDocCollector.create(10, true);
searcher.search(q, collector);
for (ScoreDoc hit: collector.topDocs().scoreDocs)
{
Document d = searcher.doc(hit.doc);
System.err.println(d.get("f1")+" "+hit.score+" "+hit.doc);
}
}
private static void addDoc(IndexWriter w, String value, float boost) throws
IOException
{
Document doc = new Document();
doc.add(new Field("f1", value, Field.Store.YES, Field.Index.ANALYZED));
doc.setBoost(boost);
w.addDocument(doc);
}
}
--
This message is automatically generated by JIRA.
If you think it was sent incorrectly, please contact your JIRA administrators:
https://issues.apache.org/jira/secure/ContactAdministrators!default.jspa
For more information on JIRA, see: http://www.atlassian.com/software/jira
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]