At Lucene, why do my backed and unprocessed documents get the same result?

At index time, I reinforce a specific document as follows:

if (myCondition) { document.SetBoost(1.2f); } 

But during the search, documents with all the exact same qualities, but with some passing and with some lack of myCondition, all have the same score.

And here is the search code:

 BooleanQuery booleanQuery = new BooleanQuery(); booleanQuery.Add(new TermQuery(new Term(FieldNames.HAS_PHOTO, "y")), BooleanClause.Occur.MUST); booleanQuery.Add(new TermQuery(new Term(FieldNames.AUTHOR_TYPE, AuthorTypes.BLOGGER)), BooleanClause.Occur.MUST_NOT); indexSearcher.Search(booleanQuery, 10); 

Can you tell me what I need to do to get documents that have been increased in order to get a higher score?

Many thanks!

+6
source share
2 answers

Lucen encodes gain by one byte (although a float is usually encoded by four bytes) using the SmallFloat # floatToByte315 method. As a result, there can be a big loss of accuracy when converting a byte to a float.

In your case, SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.2f)) returns 1f because 1f and 1.2f are too close to each other. Try to use greater momentum so your documents get different grades. (For example, 1.25, SmallFloat.byte315ToFloat(SmallFloat.floatToByte315(1.25f)) gives 1.25 f.)

+6
source

Here is the requested test program, too long to post in a comment.

 class Program { static void Main(string[] args) { RAMDirectory dir = new RAMDirectory(); IndexWriter writer = new IndexWriter(dir, new WhitespaceAnalyzer()); const string FIELD = "name"; for (int i = 0; i < 10; i++) { StringBuilder notes = new StringBuilder(); notes.AppendLine("This is a note 123 - " + i); string text = notes.ToString(); Document doc = new Document(); var field = new Field(FIELD, text, Field.Store.YES, Field.Index.NOT_ANALYZED); if (i % 2 == 0) { field.SetBoost(1.5f); doc.SetBoost(1.5f); } else { field.SetBoost(0.1f); doc.SetBoost(0.1f); } doc.Add(field); writer.AddDocument(doc); } writer.Commit(); //string TERM = QueryParser.Escape("*+*"); string TERM = "T"; IndexSearcher searcher = new IndexSearcher(dir); Query query = new PrefixQuery(new Term(FIELD, TERM)); var hits = searcher.Search(query); int count = hits.Length(); Console.WriteLine("Hits - {0}", count); for (int i = 0; i < count; i++) { var doc = hits.Doc(i); Console.WriteLine(doc.ToString()); var explain = searcher.Explain(query, i); Console.WriteLine(explain.ToString()); } } } 
+2
source

Source: https://habr.com/ru/post/900106/


All Articles