public this repo is viewable by everyone
Description: semantic repository service is intended for indexing content from different sources and maintain multi indexes for different types of content and perform different types of search. yet another solr type indexing service on top of lucene but it will gradually support content versioning and more semantic search result.
Homepage: http://hasan.we4tech.com
Clone URL: git://github.com/we4tech/semantic-repository.git
100644 60 lines (51 sloc) 2.236 kb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
/**
* $Id$
* *****************************************************************************
* Copyright (C) 2005 - 2007 somewhere in .Net ltd.
* All Rights Reserved. No use, copying or distribution of this
* work may be made except in accordance with a valid license
* agreement from somewhere in .Net LTD. This notice must be included on
* all copies, modifications and derivatives of this work.
* *****************************************************************************
* $LastChangedBy$
* $LastChangedDate$
* $LastChangedRevision$
* *****************************************************************************
*/
 
package com.ideabase.repository.core.index;
 
import org.apache.lucene.queryParser.QueryParser;
import org.apache.lucene.queryParser.ParseException;
import org.apache.lucene.analysis.Analyzer;
import org.apache.lucene.search.*;
import org.apache.lucene.index.Term;
import org.apache.lucene.index.IndexReader;
import org.apache.lucene.document.NumberTools;
import org.apache.log4j.Logger;
import org.apache.log4j.LogManager;
 
import static com.ideabase.repository.common.CommonConstants.*;
 
import java.io.IOException;
 
/**
* Extended query parser supports Number to pad
* @author <a href="http://hasan.we4tech.com">nhm tanveer...(hasan)</a>
*/
public class ExtendedQueryParser extends QueryParser {
 
  private final Logger mLog = LogManager.getLogger(getClass());
 
  public ExtendedQueryParser(final String pField, final Analyzer pAnalyzer) {
    super(pField, pAnalyzer);
  }
 
  @Override
  protected Query getRangeQuery(final String pField,
                                final String pLowerTerm,
                                final String pUpperTerm,
                                final boolean pInclusive)
      throws ParseException {
 
    final boolean includeLower = pLowerTerm != null && !"*".equals(pLowerTerm);
    final boolean includeUpper = pUpperTerm != null && !"*".equals(pUpperTerm);
    return new ConstantScoreRangeQuery(
        pField,
        includeLower ? NumberTools.longToString(Integer.parseInt(pLowerTerm)) : "",
        includeUpper ? NumberTools.longToString(Integer.parseInt(pUpperTerm)) : "*",
        includeLower, includeUpper) {
    };
  }
}