@Test public void testLongAnalyzer() throws IOException { AnalyzerDefinition analyzerDefinition = new AnalyzerDefinition(); ColumnFamilyDefinition cfDef = new ColumnFamilyDefinition(); cfDef.putToColumnDefinitions("test", new ColumnDefinition("long", true, null)); analyzerDefinition.putToColumnFamilyDefinitions("test", cfDef); BlurAnalyzer analyzer = new BlurAnalyzer(analyzerDefinition); IndexWriterConfig conf = new IndexWriterConfig(Version.LUCENE_36, analyzer); Directory dir = new RAMDirectory(); IndexWriter indexWriter = new IndexWriter(dir, conf); for (int i = 0; i < 1000; i++) { Document document = new Document(); String value = Long.toString(i); document.add(new Field("test.test", value, Store.YES, Index.ANALYZED_NO_NORMS)); FieldConverterUtil.convert(document, analyzer); indexWriter.addDocument(document); } indexWriter.close(); IndexSearcher searcher = new IndexSearcher(IndexReader.open(dir)); NumericRangeQuery<Long> query = NumericRangeQuery.newLongRange("test.test", 0L, 2L, true, true); Query rewrite = searcher.rewrite(query); TopDocs docs = searcher.search(rewrite, 100); ScoreDoc[] scoreDocs = docs.scoreDocs; assertEquals(3, docs.totalHits); for (int i = 0; i < docs.totalHits; i++) { Document document = searcher.doc(scoreDocs[i].doc); assertTrue(Integer.parseInt(document.get("test.test")) < 3); } }
public LongAnalyzer(String typeStr) { if (typeStr.startsWith(TYPE)) { int index = typeStr.indexOf(','); if (index > 0) { String s = typeStr.substring(index + 1); try { precisionStepDefault = Integer.parseInt(s); } catch (NumberFormatException e) { throw new RuntimeException("Can not parser [" + s + "] into an integer for the precisionStepDefault."); } } } else { throw new RuntimeException("Long type can not parser [" + typeStr + "]"); } }
LongAnalyzer extends ReusableAnalyzerBase implements FieldConverter { public LongAnalyzer(String typeStr) { if (typeStr.startsWith(TYPE)) { int index = typeStr.indexOf(','); if (index > 0) { String s = typeStr.substring(index + 1); try { precisionStepDefault = Integer.parseInt(s); } catch (NumberFormatException e) { throw new RuntimeException("Can not parser [" + s + "] into an integer for the precisionStepDefault."); } } } else { throw new RuntimeException("Long type can not parser [" + typeStr + "]"); } } }
LongAnalyzer extends ReusableAnalyzerBase implements FieldConverter { public LongAnalyzer(String typeStr) { if (typeStr.startsWith(TYPE)) { int index = typeStr.indexOf(','); if (index > 0) { String s = typeStr.substring(index + 1); try { precisionStepDefault = Integer.parseInt(s); } catch (NumberFormatException e) { throw new RuntimeException("Can not parser [" + s + "] into an integer for the precisionStepDefault."); } } } else { throw new RuntimeException("Long type can not parser [" + typeStr + "]"); } } LongAnalyzer(String typeStr); }
LongAnalyzer extends ReusableAnalyzerBase implements FieldConverter { public LongAnalyzer(String typeStr) { if (typeStr.startsWith(TYPE)) { int index = typeStr.indexOf(','); if (index > 0) { String s = typeStr.substring(index + 1); try { precisionStepDefault = Integer.parseInt(s); } catch (NumberFormatException e) { throw new RuntimeException("Can not parser [" + s + "] into an integer for the precisionStepDefault."); } } } else { throw new RuntimeException("Long type can not parser [" + typeStr + "]"); } } LongAnalyzer(String typeStr); @Override Fieldable convert(Fieldable fieldable); }
LongAnalyzer extends ReusableAnalyzerBase implements FieldConverter { public LongAnalyzer(String typeStr) { if (typeStr.startsWith(TYPE)) { int index = typeStr.indexOf(','); if (index > 0) { String s = typeStr.substring(index + 1); try { precisionStepDefault = Integer.parseInt(s); } catch (NumberFormatException e) { throw new RuntimeException("Can not parser [" + s + "] into an integer for the precisionStepDefault."); } } } else { throw new RuntimeException("Long type can not parser [" + typeStr + "]"); } } LongAnalyzer(String typeStr); @Override Fieldable convert(Fieldable fieldable);  }