try{
IndexWriter writer = new IndexWriter(INDEX_STORE_PATH, new StandardAnalyzer(), true);
writer.setUseCompoundFile(false);
//首先定义文本
Document doc1 = new Document();
Field f1 = new Field("bookNumber", "0000001", Field.Store.YES, Field.Index.UN_TOKENIZED);
Field f2 = new Field("bookname", "钢铁是怎样炼成的", Field.Store.YES, Field.Index.TOKENIZED);
Field f3 = new Field("publishdate", "1970-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc1.add(f1);
doc1.add(f2);
doc1.add(f3);
Document doc2 = new Document();
f1 = new Field("bookNumber", "0000002", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "钢铁战士", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "1980-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc2.add(f1);
doc2.add(f2);
doc2.add(f3);
Document doc3 = new Document();
f1 = new Field("bookNumber", "0000003", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "篱笆女人和狗", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "1990-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc3.add(f1);
doc3.add(f2);
doc3.add(f3);
Document doc4 = new Document();
f1 = new Field("bookNumber", "0000004", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "女人是水做的", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "1999-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc4.add(f1);
doc4.add(f2);
doc4.add(f3);
Document doc5 = new Document();
f1 = new Field("bookNumber", "0000005", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "英雄儿女", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "2002-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc5.add(f1);
doc5.add(f2);
doc5.add(f3);
Document doc6 = new Document();
f1 = new Field("bookNumber", "0000006", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "白毛女", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "1985-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc6.add(f1);
doc6.add(f2);
doc6.add(f3);
Document doc7 = new Document();
f1 = new Field("bookNumber", "0000007", Field.Store.YES, Field.Index.UN_TOKENIZED);
f2 = new Field("bookname", "我的兄弟和女儿", Field.Store.YES, Field.Index.TOKENIZED);
f3 = new Field("publishdate", "1978-01-01", Field.Store.YES, Field.Index.UN_TOKENIZED);
doc7.add(f1);
doc7.add(f2);
doc7.add(f3);
//构建一个查询
IndexSearcher searcher = new IndexSearcher(INDEX_STORE_PATH);
Term begin = new Term("publishdate", "1950-01-01");
Term end = new Term("publishdate", "2002-01-01");
RangeQuery rq = new RangeQuery(begin, end, false);
//构建两个SortField
Sort sort = new Sort();
//按照publishdate排序,降序
SortField sf1 = new SortField("publishdate", SortField.STRING, true);
//按bookNumber排序,升序
SortField sf2 = new SortField("bookname", SortField.INT, false);