If you wish to boost the title field for every query then it would be
easiest to boost the title clause of your query, with Query.setBoost().
Field.setBoost() should only be used when you want to give a field
different boosts in different documents, but since you want to boost all
titles by the same amount, you'll find it easier to boost at query time.
That way you can experiment with the boost amount without re-building
the index. The values of Field.setBoost() are built into the index and
are harder to change. Thus I recommend using Query.setBoost() instead.
Construct a query for each field to be searched (by hand, or with the
QueryParser), boost each of these field queries separately, then build a
BooleanQuery that combines these into a single Query that you then
execute. I hope that makes sense.
Field.setBoost(float num) 是在创建Index时创建的,并且会被写入到索引文件中。会对当前Field产生影响。
而在Document.setBoost()会对当前的文档相对于别的文档来说产生影响。这个值在创建完Document的Index时,不会被存储起来,设置的值实际上会添加到该Document的Field上,并将Boost与Field自身设置的Boost进行相加处理。
query.setBoost()是在查询时动态的设置Boost,不会对创建出来的index产生影响。
建议的做法: 为每一个要搜索的Field创建一个Query对象,分别为创建出来的query设置BOost值,然后再创建一个BooleanQuery对象(该对象将上述创建出来的Query对象合并到一起。)
对一个索引文件夹同时只能有一个IndexWriter对象,即只能存在一个锁文件(write.lock)。所以说对同一个索引文件夹设置一个IndexWriter缓冲池是不可取的