Java 类org.apache.lucene.document.FloatDocValuesField 实例源码

项目:search    文件:TestExpressionSorts.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  int numDocs = TestUtil.nextInt(random(), 2049, 4000);
  for (int i = 0; i < numDocs; i++) {
    Document document = new Document();
    document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
    document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
    document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
    document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
    document.add(new IntField("int", random().nextInt(), Field.Store.NO));
    document.add(new LongField("long", random().nextLong(), Field.Store.NO));

    document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));

    document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
    document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
    iw.addDocument(document);
  }
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
}
项目:r01fb    文件:LuceneDocumentFactoryBase.java   
/**
 * Creates a DocValue field template for a NON-language dependent type
 * @param fieldCfg
 * @return
 */
@SuppressWarnings("unchecked")
public static <FIELD extends Field> FIELD createDocValueFieldTemplate(final IndexDocumentFieldConfig<IndexDocumentValueFieldType> fieldCfg) {
    if (fieldCfg == null) return null;

    IndexDocumentFieldID fieldId = fieldCfg.getId();
    FIELD outField = null;
    switch(fieldCfg.getType()) {
    case Double:
        outField = (FIELD)(new DoubleDocValuesField(fieldId.asString(),0D));
        break;
    case Float:
        outField = (FIELD)(new FloatDocValuesField(fieldId.asString(),0F));
        break;
    default:
        throw new IllegalArgumentException(fieldCfg.getType() + "is NOT a supported type");
    }
    return outField;
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestExpressionSorts.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  int numDocs = _TestUtil.nextInt(random(), 2049, 4000);
  for (int i = 0; i < numDocs; i++) {
    Document document = new Document();
    document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
    document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
    document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
    document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
    document.add(new IntField("int", random().nextInt(), Field.Store.NO));
    document.add(new LongField("long", random().nextLong(), Field.Store.NO));

    document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));

    document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
    document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
    iw.addDocument(document);
  }
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
}
项目:elasticsearch-learning-to-rank    文件:LoggingFetchSubPhaseTests.java   
public static Document buildDoc(String text, float value) throws IOException {
    String id = UUID.randomUUID().toString();
    Document d = new Document();
    d.add(newStringField("id", id, Field.Store.YES));
    d.add(newStringField("text", text, Field.Store.NO));
    d.add(new FloatDocValuesField("score", value));
    return d;
}
项目:search    文件:TestRangeFacetCounts.java   
public void testBasicFloat() throws Exception {
  Directory d = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), d);
  Document doc = new Document();
  FloatDocValuesField field = new FloatDocValuesField("field", 0.0f);
  doc.add(field);
  for(long l=0;l<100;l++) {
    field.setFloatValue(l);
    w.addDocument(doc);
  }

  IndexReader r = w.getReader();

  FacetsCollector fc = new FacetsCollector();

  IndexSearcher s = newSearcher(r);
  s.search(new MatchAllDocsQuery(), fc);

  Facets facets = new DoubleRangeFacetCounts("field", new FloatFieldSource("field"), fc,
      new DoubleRange("less than 10", 0.0f, true, 10.0f, false),
      new DoubleRange("less than or equal to 10", 0.0f, true, 10.0f, true),
      new DoubleRange("over 90", 90.0f, false, 100.0f, false),
      new DoubleRange("90 or above", 90.0f, true, 100.0f, false),
      new DoubleRange("over 1000", 1000.0f, false, Double.POSITIVE_INFINITY, false));

  assertEquals("dim=field path=[] value=21 childCount=5\n  less than 10 (10)\n  less than or equal to 10 (11)\n  over 90 (9)\n  90 or above (10)\n  over 1000 (0)\n",
               facets.getTopChildren(10, "field").toString());

  IOUtils.close(w, r, d);
}
项目:search    文件:TestSortDocValues.java   
/** Tests sorting on type float */
public void testFloat() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // numeric order
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("30.1", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:search    文件:TestSortDocValues.java   
/** Tests sorting on type float in reverse */
public void testFloatReverse() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // reverse numeric order
  assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("-1.3", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:search    文件:TestSortDocValues.java   
/** Tests sorting on type float with a missing value */
public void testFloatMissing() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // null is treated as 0
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertNull(searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[2].doc).get("value"));

  ir.close();
  dir.close();
}
项目:search    文件:TestSortDocValues.java   
/** Tests sorting on type float, specifying the missing value should be treated as Float.MAX_VALUE */
public void testFloatMissingLast() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  SortField sortField = new SortField("value", SortField.Type.FLOAT);
  sortField.setMissingValue(Float.MAX_VALUE);
  Sort sort = new Sort(sortField);

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // null is treated as Float.MAX_VALUE
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertNull(searcher.doc(td.scoreDocs[2].doc).get("value"));

  ir.close();
  dir.close();
}
项目:NYBC    文件:TestSortDocValues.java   
/** Tests sorting on type float */
public void testFloat() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = new IndexSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // numeric order
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("30.1", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:NYBC    文件:TestSortDocValues.java   
/** Tests sorting on type float in reverse */
public void testFloatReverse() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = new IndexSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // reverse numeric order
  assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("-1.3", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:NYBC    文件:TestSearchAfter.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  int numDocs = atLeast(200);
  for (int i = 0; i < numDocs; i++) {
    Document document = new Document();
    document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
    document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
    document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
    document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
    document.add(new IntField("int", random().nextInt(), Field.Store.NO));
    document.add(new LongField("long", random().nextLong(), Field.Store.NO));

    document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));
    document.add(newStringField("bytes", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
    document.add(newStringField("bytesval", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));

    if (supportsDocValues) {
      document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
      document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
      document.add(new SortedDocValuesField("sortedbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
      document.add(new SortedDocValuesField("sortedbytesdocvaluesval", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
      document.add(new BinaryDocValuesField("straightbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
    }
    iw.addDocument(document);
  }
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
}
项目:information-retrieval-adventure    文件:IndexTimeScoringFactors.java   
/**
 * Since Lucene 6.6.0 the index time boosting has been deprecated. How we suppose to solve it now?
 */
public static void main(String[] args) throws IOException {

  Directory dir = new RAMDirectory();
  Analyzer analyzer = new StandardAnalyzer();
  IndexWriterConfig iwc = new IndexWriterConfig(analyzer);
  iwc.setOpenMode(IndexWriterConfig.OpenMode.CREATE);
  IndexWriter writer = new IndexWriter(dir, iwc);

  Document doc1 = new Document();
  doc1.add(new TextField("title", "The biggest title in the world", Store.YES));
  doc1.add(new TextField("description", "short descr", Store.YES));
  doc1.add(new FloatDocValuesField("doc_boost", 1.30f));
  writer.addDocument(doc1);

  Document doc2 = new Document();
  doc2.add(new TextField("title", "Not so important title", Store.YES));
  doc1.add(new TextField("description", "very valuable descr", Store.YES));
  doc1.add(new FloatDocValuesField("doc_boost", 3.30f));
  writer.addDocument(doc2);

  writer.close();

  IndexReader reader = DirectoryReader.open(dir);
  IndexSearcher searcher = new IndexSearcher(reader);

  Query query = new MatchAllDocsQuery();
  Query q = new FunctionScoreQuery(query, DoubleValuesSource.fromFloatField("doc_boost"));

  final ScoreDoc[] scoreDocs = searcher.search(q, 10).scoreDocs;
  for (ScoreDoc doc : scoreDocs) {
    System.out.println(doc.doc + " " + doc.score);
  }
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestRangeAccumulator.java   
public void testBasicFloat() throws Exception {
  Directory d = newDirectory();
  RandomIndexWriter w = new RandomIndexWriter(random(), d);
  Document doc = new Document();
  FloatDocValuesField field = new FloatDocValuesField("field", 0.0f);
  doc.add(field);
  for(long l=0;l<100;l++) {
    field.setFloatValue(l);
    w.addDocument(doc);
  }

  IndexReader r = w.getReader();
  w.close();

  RangeAccumulator a = new RangeAccumulator(new RangeFacetRequest<FloatRange>("field",
      new FloatRange("less than 10", 0.0f, true, 10.0f, false),
      new FloatRange("less than or equal to 10", 0.0f, true, 10.0f, true),
      new FloatRange("over 90", 90.0f, false, 100.0f, false),
      new FloatRange("90 or above", 90.0f, true, 100.0f, false),
      new FloatRange("over 1000", 1000.0f, false, Float.POSITIVE_INFINITY, false)));

  FacetsCollector fc = FacetsCollector.create(a);

  IndexSearcher s = newSearcher(r);
  s.search(new MatchAllDocsQuery(), fc);
  List<FacetResult> result = fc.getFacetResults();
  assertEquals(1, result.size());
  assertEquals("field (0)\n  less than 10 (10)\n  less than or equal to 10 (11)\n  over 90 (9)\n  90 or above (10)\n  over 1000 (0)\n", FacetTestUtils.toSimpleString(result.get(0)));

  r.close();
  d.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSortDocValues.java   
/** Tests sorting on type float */
public void testFloat() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // numeric order
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("30.1", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSortDocValues.java   
/** Tests sorting on type float in reverse */
public void testFloatReverse() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  doc.add(new FloatDocValuesField("value", 30.1F));
  doc.add(newStringField("value", "30.1", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT, true));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // reverse numeric order
  assertEquals("30.1", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("-1.3", searcher.doc(td.scoreDocs[2].doc).get("value"));
  assertNoFieldCaches();

  ir.close();
  dir.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSortDocValues.java   
/** Tests sorting on type float with a missing value */
public void testFloatMissing() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  Sort sort = new Sort(new SortField("value", SortField.Type.FLOAT));

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // null is treated as 0
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertNull(searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[2].doc).get("value"));

  ir.close();
  dir.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSortDocValues.java   
/** Tests sorting on type float, specifying the missing value should be treated as Float.MAX_VALUE */
public void testFloatMissingLast() throws IOException {
  Directory dir = newDirectory();
  RandomIndexWriter writer = new RandomIndexWriter(random(), dir);
  Document doc = new Document();
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", -1.3F));
  doc.add(newStringField("value", "-1.3", Field.Store.YES));
  writer.addDocument(doc);
  doc = new Document();
  doc.add(new FloatDocValuesField("value", 4.2F));
  doc.add(newStringField("value", "4.2", Field.Store.YES));
  writer.addDocument(doc);
  IndexReader ir = writer.getReader();
  writer.close();

  IndexSearcher searcher = newSearcher(ir);
  SortField sortField = new SortField("value", SortField.Type.FLOAT);
  sortField.setMissingValue(Float.MAX_VALUE);
  Sort sort = new Sort(sortField);

  TopDocs td = searcher.search(new MatchAllDocsQuery(), 10, sort);
  assertEquals(3, td.totalHits);
  // null is treated as Float.MAX_VALUE
  assertEquals("-1.3", searcher.doc(td.scoreDocs[0].doc).get("value"));
  assertEquals("4.2", searcher.doc(td.scoreDocs[1].doc).get("value"));
  assertNull(searcher.doc(td.scoreDocs[2].doc).get("value"));

  ir.close();
  dir.close();
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestSearchAfter.java   
@Override
public void setUp() throws Exception {
  super.setUp();
  dir = newDirectory();
  RandomIndexWriter iw = new RandomIndexWriter(random(), dir);
  int numDocs = atLeast(200);
  for (int i = 0; i < numDocs; i++) {
    Document document = new Document();
    document.add(newTextField("english", English.intToEnglish(i), Field.Store.NO));
    document.add(newTextField("oddeven", (i % 2 == 0) ? "even" : "odd", Field.Store.NO));
    document.add(newStringField("byte", "" + ((byte) random().nextInt()), Field.Store.NO));
    document.add(newStringField("short", "" + ((short) random().nextInt()), Field.Store.NO));
    document.add(new IntField("int", random().nextInt(), Field.Store.NO));
    document.add(new LongField("long", random().nextLong(), Field.Store.NO));

    document.add(new FloatField("float", random().nextFloat(), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));
    document.add(newStringField("bytes", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
    document.add(newStringField("bytesval", _TestUtil.randomRealisticUnicodeString(random()), Field.Store.NO));
    document.add(new DoubleField("double", random().nextDouble(), Field.Store.NO));

    if (supportsDocValues) {
      document.add(new NumericDocValuesField("intdocvalues", random().nextInt()));
      document.add(new FloatDocValuesField("floatdocvalues", random().nextFloat()));
      document.add(new SortedDocValuesField("sortedbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
      document.add(new SortedDocValuesField("sortedbytesdocvaluesval", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
      document.add(new BinaryDocValuesField("straightbytesdocvalues", new BytesRef(_TestUtil.randomRealisticUnicodeString(random()))));
    }
    iw.addDocument(document);
  }
  reader = iw.getReader();
  iw.close();
  searcher = newSearcher(reader);
}
项目:search    文件:TestBackwardsCompatibility3x.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}
项目:search    文件:TestBackwardsCompatibility.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  doc.add(new SortedSetDocValuesField("dvSortedSet", ref));
  doc.add(new SortedNumericDocValuesField("dvSortedNumeric", id));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}
项目:NYBC    文件:TestBackwardsCompatibility3x.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}
项目:NYBC    文件:TestBackwardsCompatibility.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestBackwardsCompatibility3x.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}
项目:Maskana-Gestor-de-Conocimiento    文件:TestBackwardsCompatibility.java   
private void addDoc(IndexWriter writer, int id) throws IOException
{
  Document doc = new Document();
  doc.add(new TextField("content", "aaa", Field.Store.NO));
  doc.add(new StringField("id", Integer.toString(id), Field.Store.YES));
  FieldType customType2 = new FieldType(TextField.TYPE_STORED);
  customType2.setStoreTermVectors(true);
  customType2.setStoreTermVectorPositions(true);
  customType2.setStoreTermVectorOffsets(true);
  doc.add(new Field("autf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("utf8", "Lu\uD834\uDD1Ece\uD834\uDD60ne \u0000 \u2620 ab\ud917\udc17cd", customType2));
  doc.add(new Field("content2", "here is more content with aaa aaa aaa", customType2));
  doc.add(new Field("fie\u2C77ld", "field with non-ascii name", customType2));
  // add numeric fields, to test if flex preserves encoding
  doc.add(new IntField("trieInt", id, Field.Store.NO));
  doc.add(new LongField("trieLong", (long) id, Field.Store.NO));
  // add docvalues fields
  doc.add(new NumericDocValuesField("dvByte", (byte) id));
  byte bytes[] = new byte[] {
    (byte)(id >>> 24), (byte)(id >>> 16),(byte)(id >>> 8),(byte)id
  };
  BytesRef ref = new BytesRef(bytes);
  doc.add(new BinaryDocValuesField("dvBytesDerefFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesDerefVar", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedFixed", ref));
  doc.add(new SortedDocValuesField("dvBytesSortedVar", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightFixed", ref));
  doc.add(new BinaryDocValuesField("dvBytesStraightVar", ref));
  doc.add(new DoubleDocValuesField("dvDouble", (double)id));
  doc.add(new FloatDocValuesField("dvFloat", (float)id));
  doc.add(new NumericDocValuesField("dvInt", id));
  doc.add(new NumericDocValuesField("dvLong", id));
  doc.add(new NumericDocValuesField("dvPacked", id));
  doc.add(new NumericDocValuesField("dvShort", (short)id));
  doc.add(new SortedSetDocValuesField("dvSortedSet", ref));
  // a field with both offsets and term vectors for a cross-check
  FieldType customType3 = new FieldType(TextField.TYPE_STORED);
  customType3.setStoreTermVectors(true);
  customType3.setStoreTermVectorPositions(true);
  customType3.setStoreTermVectorOffsets(true);
  customType3.setIndexOptions(IndexOptions.DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS);
  doc.add(new Field("content5", "here is more content with aaa aaa aaa", customType3));
  // a field that omits only positions
  FieldType customType4 = new FieldType(TextField.TYPE_STORED);
  customType4.setStoreTermVectors(true);
  customType4.setStoreTermVectorPositions(false);
  customType4.setStoreTermVectorOffsets(true);
  customType4.setIndexOptions(IndexOptions.DOCS_AND_FREQS);
  doc.add(new Field("content6", "here is more content with aaa aaa aaa", customType4));
  // TODO: 
  //   index different norms types via similarity (we use a random one currently?!)
  //   remove any analyzer randomness, explicitly add payloads for certain fields.
  writer.addDocument(doc);
}