Kolya Kliment Kolya Kliment - 1 year ago 73
Java Question

Index Markdown Files Using Lucene in Java

How can I index markdown files using Java & lucene so that proper weight is designated to Markdown file's Headers, Emphasis etc.

Answer Source

For the latest version of Lucene ( 6.5.1 ) , refer Scoring — Basics section at the bottom.

In older lucene versions, you could have added boost at document level too, that is removed now and I guess that is not needed for your case either.

So, for your case, you simply need to call, setBoost() method for fields that you add to document.

Index-time boost by calling Field.setBoost() before a document is added to the index.
Query-time boost by applying a boost to a query by wrapping with BoostQuery.

In my codes, I have followed second approach where I boost score during searching by wrapping my Fuzzy , Phrase , Term or WildCard queries in BoostQuery.

Refer BoostQuery and its constructor , BoostQuery(Query query, float boost)

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download