public void warmUpContactSearcher(IndexSearcher newSearcher) throws Exception {
final Sort sortByName = new Sort(new SortField(FLD_NAME_LAST, SortField.STRING));
final Analyzer analyzer = LuceneSearcher.getAnalyzer();
final QueryParser parser = new QueryParser(FLD_COMPANY_KEYWORDS, analyzer);
final int maxContactResults = 100;
logger.debug("Contact search: company keyword jigsaw");
Query query = getKeywordQuery(LuceneSearcher.FLD_COMPANY_KEYWORDS, "jigsaw");
Sort sort = new Sort(new SortField(LuceneSearcher.FLD_COMPANY_NAME,
SortField.STRING, false));
newSearcher.search(query, null, maxContactResults, sort);
logger.debug("Contact search: company keyword intel");
query = new TermQuery(new Term(FLD_COMPANY_KEYWORDS, "intel"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: company keyword Intel Corporation");
query = LuceneSearcher.getInstance().getKeywordQuery(FLD_COMPANY_KEYWORDS,
"Intel Corporation");
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: company keyword :intel");
query = parser.parse(FLD_COMPANY_KEYWORDS + ":Intel");
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: title keyword director");
query = new TermQuery(new Term(FLD_TITLE_KEYWORDS, "director"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: title keyword :Director");
query = parser.parse(FLD_TITLE_KEYWORDS + ":Director");
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: company class1 1100000");
query = new TermQuery(new Term(FLD_COMPANY_CLASS1, "1100000"));
newSearcher.search(query, null, maxContactResults, sortByName);
char lastChar = 'z';
String alphabet = "abcdefghijklmnopqrstuvwxy";
for (int i = 0; i < alphabet.length(); i++) {
String lowerName = alphabet.substring(i, i + 1);
logger.debug("Contact search: last name " + lowerName + "-" + lastChar);
query = new ConstantScoreRangeQuery(FLD_NAME_FIRST, lowerName,
String.valueOf(lastChar), true, false);
newSearcher.search(query, null, maxContactResults, sortByName);
}
logger.debug("Contact search: last name smith");
query = new TermQuery(new Term(FLD_NAME_LAST, "smith"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: company keyword intel, title keyword director");
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(FLD_COMPANY_KEYWORDS, "intel")),
BooleanClause.Occur.MUST);
booleanQuery.add(new TermQuery(new Term(FLD_TITLE_KEYWORDS, "director")),
BooleanClause.Occur.MUST);
newSearcher.search(booleanQuery, null, maxContactResults, sortByName);
logger.debug("Contact search: company keyword intel, title keyword :Director");
query = parser.parse("+" + FLD_COMPANY_KEYWORDS + ":Intel +" + FLD_TITLE_KEYWORDS
+ ":Director");
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: dept1 " + Constant.DEPT_ITIS);
query = new TermQuery(new Term(FLD_DEPT1, "" + Constant.DEPT_ITIS));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: dept1 " + Constant.DEPT_ITIS +
", rank directory, state CA ");
booleanQuery = new BooleanQuery();
Query dept = new TermQuery(new Term(FLD_DEPT1, "" + Constant.DEPT_ITIS));
booleanQuery.add(dept, BooleanClause.Occur.MUST);
Query rank = new TermQuery(new Term(FLD_RANK, "" + Constant.RANK_DIRECTOR));
booleanQuery.add(rank, BooleanClause.Occur.MUST);
Query state = new TermQuery(new Term(FLD_STATE, ""
+ GeoConstant.US_STATE_CALIFORNIA));
booleanQuery.add(state, BooleanClause.Occur.MUST);
newSearcher.search(booleanQuery, null, maxContactResults, sortByName);
logger.debug("Contact search: area code 415");
query = new TermQuery(new Term(FLD_AREA_CODE, "415"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: rank other");
query = new TermQuery(new Term(FLD_RANK, "500"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: state 209");
query = new TermQuery(new Term(FLD_STATE, "209"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: company id C- 0000023080");
query = new TermQuery(new Term(FLD_COMPANY_ID, "C- 0000023080"));
newSearcher.search(query, null, maxContactResults, sortByName);
logger.debug("Contact search: last name aa - al");
booleanQuery = new BooleanQuery();
booleanQuery.add(new TermQuery(new Term(FLD_IS_SEARCH_DISABLED,
Boolean.FALSE.toString())), BooleanClause.Occur.MUST);
booleanQuery.add(new ConstantScoreRangeQuery(FLD_NAME_LAST, "aa", "al", true,
false), BooleanClause.Occur.MUST);
newSearcher.search(booleanQuery, null, maxContactResults, sortByName);
logger.debug("Contact search: last name aa - al");
String queryText = "+(class1:1020000 class2:1020000 class3:1020000 class1:1030000 class2:1030000 class3:1030000 class1:1230000 class2:1230000 class3:1230000 class1:1060000 class2:1060000 class3:1060000 class1:1070000 class2:1070000 class3:1070000 class1:1100000 class2:1100000 class3:1100000 class1:1110000 class2:1110000 class3:1110000 class1:1120000 class2:1120000 class3:1120000 class1:1140000 class2:1140000 class3:1140000 class1:1160000 class2:1160000 class3:1160000 class1:1180000 class2:1180000 class3:1180000 class1:1190000 class2:1190000 class3:1190000 class1:1200000 class2:1200000 class3:1200000 class1:1210000 class2:1210000 class3:1210000 class1:1220000 class2:1220000 class3:1220000) +type:1 +(employees:40 employees:20 employees:30) +(revenue:40 revenue:20 revenue:30) +(rank:10 rank:30 rank:20) +(dept1:10 dept2:10 dept3:10 dept1:20 dept2:20 dept3:20) +country:9000 +state:9005";
logger.debug("Contact search: " + queryText);
query = parser.parse(queryText);
newSearcher.search(query, null, maxContactResults, sortByName);
}
分享到:
相关推荐
本文将深入探讨《看大师如何重构代码(java程序员必看)》这一主题,解析代码重构的核心概念、实践方法以及其对Java编程的深远影响。 ### 代码重构的概念 代码重构是指在不改变代码外部行为的前提下,对其内部结构...
《重构:改善既有代码设计》是一本由Martin Fowler所著的经典IT著作,它详细阐述了在软件开发过程中如何通过重构来提升代码质量、可读性和维护性。重构是一种系统性的方法,旨在不改变软件外在行为的前提下,改进其...
一直很喜欢重构这本书,但是由于自己记性不太好,书看过之后其中的方法总是记不住,于是想如果有电子版的重构书就好了,工作中遇到重构的问题可以随时打开查阅。在网上搜索了许久,发现重构这本书有英文chm版本的,...
代码重构是一种重要的软件开发实践,旨在改进代码的结构和可读性,而不改变其外部行为。这个压缩包文件“代码重构源码(包含重构前后代码)”提供了面向对象编程领域中的一个实例,具体是对影片出租店租赁程序的重构...
你曾去想重构一个很老的模块,但是你只看了一眼你就恶心极了。文档,奇怪的函数和类的命名,等等,整个模块就像一个带着脚镣的衣衫褴褛的人,虽然能走,但是其已经让人感到很不舒服。面对这种情况,真正的程序员会是...
java代码重构以前忽视了,最近在看 字字珠玑,相见恨晚
其次,我们来看《重构-改善既有代码的设计》。这是由Martin Fowler所著的经典著作,书中详细阐述了代码重构的概念、原则和方法。重构是指在不改变软件外部行为的前提下,改进其内部结构,以提高代码的可读性、可维护...
重构:改善既有代码的设计 中文PDF清晰版 Martin Fowler和《重构:改善既有代码的设计》(中文版)另几位作者清楚揭示了重构过程,他们为面向对象软件开发所做的贡献,难以衡量。《重构:改善既有代码的设计》(中文版)...
总共43页,内含对代码重构的详细介绍,还有很多的例子介绍,花很短时间就能看完
《重构:改善既有代码的设计》是一本在软件开发领域具有深远影响的经典著作,作者是马丁·福勒(Martin Fowler)。这本书主要关注的是如何通过一系列微小的改进步骤,即重构,来提升现有代码的质量和可维护性。在Web...
Martin Fowler和《重构:改善既有代码的设计》(中文版)另几位作者清楚揭示了重构过程,他们为面向对象软件开发所做的贡献,难以衡量。《重构:改善既有代码的设计》(中文版)解释重构的原理(principles)和最佳实践...
重构-改善即有代码的设计.pdf,经典,经典,经典,必看
在本篇博客“代码重构-以贪吃蛇为示例(四)-继续封装”中,作者通过实现贪吃蛇游戏来阐述代码重构的重要性和具体实践。贪吃蛇游戏是许多程序员学习编程时的入门项目,它包含了基本的逻辑控制、用户输入处理以及游戏...
描述中提到的"看了那些很乱的代码,让我头痛",这是一个普遍现象,表明了重构的必要性。当代码变得难以理解和修改时,不仅会降低开发效率,还可能引入新的错误。因此,进行重构就像给老旧的建筑物进行内部装修,保持...
状态模式是一种行为设计模式,它允许对象在内部状态改变时改变其行为,对象看起来似乎修改了它的类。这种模式常用于处理对象的状态变化,并且在不同的状态下,对象的行为也相应地变化。 首先,我们来理解状态模式的...
某些项目如Extract Method和Move Field看起来可能很浅显,但不要掉以轻心,因为理解这类技术正是有条不紊地进行重构的关键。本书所提的这些重构准则将帮助你一次一小步地修改你的代码,这就减少了过程中的风险。很快...
某些项目如Extract Method和Move Field看起来可能很浅显,但不要掉以轻心,因为理解这类技术正是有条不紊地进行重构的关键。本书所提的这些重构准则将帮助你壹次壹小步地修改你的代码,这就减少了过程中的风险。很快...