public Query parse() throws ParseException { String pattern = qstr; int idx = qstr.indexOf("title:"); if (idx < 0) return keyParser.parse(qstr); pattern = qstr.substring(0, idx); String title = qstr.substring(idx + 6); StringBuilder builder = new StringBuilder(); for (int i = 0; i < title.length(); i++) { char c = title.charAt(i); for (int k = 0; k < TpWorkingData.SPECIALS.length; k++) { if (c != TpWorkingData.SPECIALS[k]) continue; builder.append('\\'); break; } builder.append(c); } title = builder.toString(); BooleanQuery patternQuery = new BooleanQuery(); patternQuery.add(keyParser.parse(pattern), BooleanClause.Occur.SHOULD); if (title.trim().length() > 0) { patternQuery.add(titleParser.parse(title), BooleanClause.Occur.SHOULD); } // return keyParser.parse(qstr); // System.out.println(" thay co "+ patternQuery); return patternQuery; }
@SuppressWarnings("unused") List<Query> createShouldQueries(Map<Short, Collection<?>> records) throws ParseException { List<Query> list = new ArrayList<Query>(); // today Calendar calendar = Calendar.getInstance(); long max = calendar.getTimeInMillis(); calendar.set(Calendar.HOUR, 0); long min = calendar.getTimeInMillis(); StringBuilder builder = new StringBuilder(); builder.append('[').append(min).append(" TO ").append(max).append(']'); Query timeQuery = timeParser.parse(builder.toString()); timeQuery.setBoost(10.0f); list.add(timeQuery); // System.out.println(" boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); // yestoday max = min; calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = timeParser.parse(builder.toString()); timeQuery.setBoost(8.0f); list.add(timeQuery); // System.out.println(" boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); max = min; calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = timeParser.parse(builder.toString()); timeQuery.setBoost(7.0f); list.add(timeQuery); // System.out.println(" boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); max = min; calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = timeParser.parse(builder.toString()); timeQuery.setBoost(4.0f); list.add(timeQuery); // System.out.println(" boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); max = min; calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 2); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = timeParser.parse(builder.toString()); timeQuery.setBoost(2.0f); list.add(timeQuery); // System.out.println(" boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); // for source time calendar = Calendar.getInstance(); max = calendar.getTimeInMillis(); calendar.set(Calendar.HOUR, 0); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = sourceTimeParser.parse(builder.toString()); timeQuery.setBoost(7.0f); list.add(timeQuery); // System.out.println(" source time boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); calendar = Calendar.getInstance(); max = calendar.getTimeInMillis(); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = sourceTimeParser.parse(builder.toString()); timeQuery.setBoost(5.0f); list.add(timeQuery); // System.out.println(" source time boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost() ); calendar = Calendar.getInstance(); max = calendar.getTimeInMillis(); calendar.set(Calendar.DATE, calendar.get(Calendar.DATE) - 1); min = calendar.getTimeInMillis(); builder.setLength(0); builder.append('[').append(min).append(" TO ").append(max).append(']'); timeQuery = sourceTimeParser.parse(builder.toString()); timeQuery.setBoost(2.0f); list.add(timeQuery); // System.out.println(" source time boost " + calendar.get(Calendar.DATE) + " : "+ // timeQuery.getBoost()); // TermRangeQuery tquery = new TermRangeQuery( // "time", String.valueOf(min), String.valueOf(max), true, true); // list.add(tquery); return list; }