List of usage examples for org.apache.lucene.document DoubleDocValuesField DoubleDocValuesField
public DoubleDocValuesField(String name, double value)
From source file:cn.codepub.redis.directory.Main.java
License:Apache License
private static Document addDocument(int i) { Document document = new Document(); document.add(new StringField("key1", "key" + i, Field.Store.YES)); document.add(new IntField("key2", i * 100000, Field.Store.YES)); document.add(new FloatField("key3", (float) i * 100000, Field.Store.YES)); document.add(new LongField("key4", (long) i * 100000, Field.Store.YES)); document.add(new DoubleField("key5", (double) i * 100000, Field.Store.YES)); document.add(new TextField("key6", RandomStringUtils.randomAlphabetic(10), Field.Store.YES)); document.add(new StringField("key7", RandomStringUtils.randomAlphabetic(5), Field.Store.YES)); document.add(new BinaryDocValuesField("key8", new BytesRef(RandomStringUtils.randomAlphabetic(5)))); document.add(new DoubleDocValuesField("key9", RandomUtils.nextDouble(0, 1000))); document.add(new FloatDocValuesField("key10", RandomUtils.nextFloat(0, 1000))); document.add(new LongField("key11", (long) i * 50000, Field.Store.YES)); document.add(new IntField("key12", i * 50000, Field.Store.YES)); document.add(new FloatField("key13", (float) i * 50000, Field.Store.YES)); document.add(new DoubleField("key14", (double) i * 50000, Field.Store.YES)); document.add(new StringField("key15", RandomStringUtils.randomAlphabetic(6), Field.Store.YES)); return document; }
From source file:com.querydsl.lucene5.LuceneQueryTest.java
License:Apache License
private Document createDocument(final String docTitle, final String docAuthor, final String docText, final int docYear, final double docGross) { Document doc = new Document(); // Reusing field for performance if (titleField == null) { titleField = new TextField("title", docTitle, Store.YES); doc.add(titleField);//from ww w . j a v a2 s . c om titleSortedField = new SortedDocValuesField("title", new BytesRef(docTitle)); doc.add(titleSortedField); } else { titleField.setStringValue(docTitle); titleSortedField.setBytesValue(new BytesRef(docTitle)); doc.add(titleField); doc.add(titleSortedField); } if (authorField == null) { authorField = new TextField("author", docAuthor, Store.YES); doc.add(authorField); authorSortedField = new SortedDocValuesField("author", new BytesRef(docAuthor)); doc.add(authorSortedField); } else { authorField.setStringValue(docAuthor); authorSortedField.setBytesValue(new BytesRef(docAuthor)); doc.add(authorField); doc.add(authorSortedField); } if (textField == null) { textField = new TextField("text", docText, Store.YES); doc.add(textField); textSortedField = new SortedDocValuesField("text", new BytesRef(docText)); doc.add(textSortedField); } else { textField.setStringValue(docText); textSortedField.setBytesValue(new BytesRef(docText)); doc.add(textField); doc.add(textSortedField); } if (yearField == null) { yearField = new IntField("year", docYear, Store.YES); doc.add(yearField); yearSortedField = new NumericDocValuesField("year", docYear); doc.add(yearSortedField); } else { yearField.setIntValue(docYear); yearSortedField.setLongValue(docYear); doc.add(yearField); doc.add(yearSortedField); } if (grossField == null) { grossField = new DoubleField("gross", docGross, Store.YES); doc.add(grossField); grossSortedField = new DoubleDocValuesField("gross", docGross); doc.add(grossSortedField); } else { grossField.setDoubleValue(docGross); grossSortedField.setDoubleValue(docGross); doc.add(grossField); doc.add(grossSortedField); } return doc; }
From source file:com.qwazr.search.bench.test.Merging.UpdateNumericDocValuesTest.java
License:Apache License
protected Field getField(String id) { return new DoubleDocValuesField("dv", id.hashCode()); }
From source file:com.qwazr.search.field.DoubleDocValuesType.java
License:Apache License
@Override final public void fillValue(final Object value, final FieldConsumer consumer) { if (value instanceof Number) consumer.accept(new DoubleDocValuesField(fieldName, ((Number) value).doubleValue())); else// ww w.java2s. c o m consumer.accept(new DoubleDocValuesField(fieldName, Double.parseDouble(value.toString()))); }
From source file:com.tuplejump.stargate.Fields.java
License:Apache License
private static Field numericDocValuesField(String name, final AbstractType abstractType, final ByteBuffer byteBufferValue) { final String stripedName = striped + name; CQL3Type cqlType = abstractType.asCQL3Type(); if (cqlType == CQL3Type.Native.TIMESTAMP) { Date date = (Date) abstractType.compose(byteBufferValue); return new NumericDocValuesField(stripedName, date.getTime()); }/*from ww w .j a va 2 s.com*/ Number value = (Number) abstractType.compose(byteBufferValue); if (cqlType == CQL3Type.Native.INT || cqlType == CQL3Type.Native.VARINT || cqlType == CQL3Type.Native.BIGINT || cqlType == CQL3Type.Native.COUNTER) { return new NumericDocValuesField(stripedName, value.longValue()); } else if (cqlType == CQL3Type.Native.FLOAT) { return new FloatDocValuesField(stripedName, value.floatValue()); } else if (cqlType == CQL3Type.Native.DECIMAL || cqlType == CQL3Type.Native.DOUBLE) { return new DoubleDocValuesField(stripedName, value.doubleValue()); } else throw new IllegalArgumentException(String.format("Invalid type for numeric doc values <%s>", cqlType)); }
From source file:com.yida.framework.lucene5.facet.DistanceFacetsExample.java
License:Creative Commons License
/** * /*from ww w .ja v a 2 s . com*/ */ public void index() throws IOException { IndexWriter writer = new IndexWriter(indexDir, new IndexWriterConfig(new WhitespaceAnalyzer())); // ??(?FacetField) Document doc = new Document(); doc.add(new DoubleDocValuesField("latitude", 40.759011)); doc.add(new DoubleDocValuesField("longitude", -73.9844722)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleDocValuesField("latitude", 40.718266)); doc.add(new DoubleDocValuesField("longitude", -74.007819)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleDocValuesField("latitude", 40.7051157)); doc.add(new DoubleDocValuesField("longitude", -74.0088305)); writer.addDocument(doc); /*doc.add(new DoubleField("latitude", 40.759011, Field.Store.YES)); doc.add(new DoubleField("longitude", -73.9844722, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("latitude", 40.718266, Field.Store.YES)); doc.add(new DoubleField("longitude", -74.007819, Field.Store.YES)); writer.addDocument(doc); doc = new Document(); doc.add(new DoubleField("latitude", 40.7051157, Field.Store.YES)); doc.add(new DoubleField("longitude", -74.0088305, Field.Store.YES)); writer.addDocument(doc); */ searcher = new IndexSearcher(DirectoryReader.open(writer, true)); writer.commit(); writer.close(); }
From source file:org.apache.jackrabbit.oak.plugins.index.lucene.LuceneIndexEditor.java
License:Apache License
private boolean addTypedOrderedFields(List<Field> fields, PropertyState property, String pname, PropertyDefinition pd) {/*from w w w.j a v a 2s .c o m*/ // Ignore and warn if property multi-valued as not supported if (property.getType().isArray()) { log.warn( "[{}] Ignoring ordered property {} of type {} for path {} as multivalued ordered property not supported", getIndexName(), pname, Type.fromTag(property.getType().tag(), true), getPath()); return false; } int tag = property.getType().tag(); int idxDefinedTag = pd.getType(); // Try converting type to the defined type in the index definition if (tag != idxDefinedTag) { log.debug( "[{}] Ordered property defined with type {} differs from property {} with type {} in " + "path {}", getIndexName(), Type.fromTag(idxDefinedTag, false), property.toString(), Type.fromTag(tag, false), getPath()); tag = idxDefinedTag; } String name = FieldNames.createDocValFieldName(pname); boolean fieldAdded = false; Field f = null; try { if (tag == Type.LONG.tag()) { //TODO Distinguish fields which need to be used for search and for sort //If a field is only used for Sort then it can be stored with less precision f = new NumericDocValuesField(name, property.getValue(Type.LONG)); } else if (tag == Type.DATE.tag()) { String date = property.getValue(Type.DATE); f = new NumericDocValuesField(name, FieldFactory.dateToLong(date)); } else if (tag == Type.DOUBLE.tag()) { f = new DoubleDocValuesField(name, property.getValue(Type.DOUBLE)); } else if (tag == Type.BOOLEAN.tag()) { f = new SortedDocValuesField(name, new BytesRef(property.getValue(Type.BOOLEAN).toString())); } else if (tag == Type.STRING.tag()) { f = new SortedDocValuesField(name, new BytesRef(property.getValue(Type.STRING))); } if (f != null) { fields.add(f); fieldAdded = true; } } catch (Exception e) { log.warn( "[{}] Ignoring ordered property. Could not convert property {} of type {} to type {} for path {}", getIndexName(), pname, Type.fromTag(property.getType().tag(), false), Type.fromTag(tag, false), getPath(), e); } return fieldAdded; }
From source file:org.apache.solr.legacy.BBoxStrategy.java
License:Apache License
private Field[] createIndexableFields(Rectangle bbox) { Field[] fields = new Field[fieldsLen]; int idx = -1; if (hasStored) { fields[++idx] = new StoredField(field_minX, bbox.getMinX()); fields[++idx] = new StoredField(field_minY, bbox.getMinY()); fields[++idx] = new StoredField(field_maxX, bbox.getMaxX()); fields[++idx] = new StoredField(field_maxY, bbox.getMaxY()); }// w w w.j ava 2s. c o m if (hasDocVals) { fields[++idx] = new DoubleDocValuesField(field_minX, bbox.getMinX()); fields[++idx] = new DoubleDocValuesField(field_minY, bbox.getMinY()); fields[++idx] = new DoubleDocValuesField(field_maxX, bbox.getMaxX()); fields[++idx] = new DoubleDocValuesField(field_maxY, bbox.getMaxY()); } if (hasPointVals) { fields[++idx] = new DoublePoint(field_minX, bbox.getMinX()); fields[++idx] = new DoublePoint(field_minY, bbox.getMinY()); fields[++idx] = new DoublePoint(field_maxX, bbox.getMaxX()); fields[++idx] = new DoublePoint(field_maxY, bbox.getMaxY()); } if (legacyNumericFieldType != null) { fields[++idx] = new LegacyDoubleField(field_minX, bbox.getMinX(), legacyNumericFieldType); fields[++idx] = new LegacyDoubleField(field_minY, bbox.getMinY(), legacyNumericFieldType); fields[++idx] = new LegacyDoubleField(field_maxX, bbox.getMaxX(), legacyNumericFieldType); fields[++idx] = new LegacyDoubleField(field_maxY, bbox.getMaxY(), legacyNumericFieldType); } if (xdlFieldType != null) { fields[++idx] = new Field(field_xdl, bbox.getCrossesDateLine() ? "T" : "F", xdlFieldType); } assert idx == fields.length - 1; return fields; }
From source file:org.apache.solr.legacy.PointVectorStrategy.java
License:Apache License
/** @see #createIndexableFields(org.locationtech.spatial4j.shape.Shape) */ public Field[] createIndexableFields(Point point) { Field[] fields = new Field[fieldsLen]; int idx = -1; if (hasStored) { fields[++idx] = new StoredField(fieldNameX, point.getX()); fields[++idx] = new StoredField(fieldNameY, point.getY()); }/*from w w w . java2 s. c o m*/ if (hasDocVals) { fields[++idx] = new DoubleDocValuesField(fieldNameX, point.getX()); fields[++idx] = new DoubleDocValuesField(fieldNameY, point.getY()); } if (hasPointVals) { fields[++idx] = new DoublePoint(fieldNameX, point.getX()); fields[++idx] = new DoublePoint(fieldNameY, point.getY()); } if (legacyNumericFieldType != null) { fields[++idx] = new LegacyDoubleField(fieldNameX, point.getX(), legacyNumericFieldType); fields[++idx] = new LegacyDoubleField(fieldNameY, point.getY(), legacyNumericFieldType); } assert idx == fields.length - 1; return fields; }
From source file:org.elasticsearch.search.aggregations.bucket.sampler.DiversifiedSamplerTests.java
License:Apache License
public void testDiversifiedSampler() throws Exception { String data[] = {/*from www. j a v a2 s . c o m*/ // "id,cat,name,price,inStock,author_t,series_t,sequence_i,genre_s,genre_id", "0553573403,book,A Game of Thrones,7.99,true,George R.R. Martin,A Song of Ice and Fire,1,fantasy,0", "0553579908,book,A Clash of Kings,7.99,true,George R.R. Martin,A Song of Ice and Fire,2,fantasy,0", "055357342X,book,A Storm of Swords,7.99,true,George R.R. Martin,A Song of Ice and Fire,3,fantasy,0", "0553293354,book,Foundation,17.99,true,Isaac Asimov,Foundation Novels,1,scifi,1", "0812521390,book,The Black Company,6.99,false,Glen Cook,The Chronicles of The Black Company,1,fantasy,0", "0812550706,book,Ender's Game,6.99,true,Orson Scott Card,Ender,1,scifi,1", "0441385532,book,Jhereg,7.95,false,Steven Brust,Vlad Taltos,1,fantasy,0", "0380014300,book,Nine Princes In Amber,6.99,true,Roger Zelazny,the Chronicles of Amber,1,fantasy,0", "0805080481,book,The Book of Three,5.99,true,Lloyd Alexander,The Chronicles of Prydain,1,fantasy,0", "080508049X,book,The Black Cauldron,5.99,true,Lloyd Alexander,The Chronicles of Prydain,2,fantasy,0" }; Directory directory = newDirectory(); RandomIndexWriter indexWriter = new RandomIndexWriter(random(), directory); for (String entry : data) { String[] parts = entry.split(","); Document document = new Document(); document.add(new SortedDocValuesField("id", new BytesRef(parts[0]))); document.add(new StringField("cat", parts[1], Field.Store.NO)); document.add(new TextField("name", parts[2], Field.Store.NO)); document.add(new DoubleDocValuesField("price", Double.valueOf(parts[3]))); document.add(new StringField("inStock", parts[4], Field.Store.NO)); document.add(new StringField("author", parts[5], Field.Store.NO)); document.add(new StringField("series", parts[6], Field.Store.NO)); document.add(new StringField("sequence", parts[7], Field.Store.NO)); document.add(new SortedDocValuesField("genre", new BytesRef(parts[8]))); document.add(new NumericDocValuesField("genre_id", Long.valueOf(parts[9]))); indexWriter.addDocument(document); } indexWriter.close(); IndexReader indexReader = DirectoryReader.open(directory); IndexSearcher indexSearcher = new IndexSearcher(indexReader); MappedFieldType genreFieldType = new KeywordFieldMapper.KeywordFieldType(); genreFieldType.setName("genre"); genreFieldType.setHasDocValues(true); Consumer<InternalSampler> verify = result -> { Terms terms = result.getAggregations().get("terms"); assertEquals(2, terms.getBuckets().size()); assertEquals("0805080481", terms.getBuckets().get(0).getKeyAsString()); assertEquals("0812550706", terms.getBuckets().get(1).getKeyAsString()); }; testCase(indexSearcher, genreFieldType, "map", verify); testCase(indexSearcher, genreFieldType, "global_ordinals", verify); testCase(indexSearcher, genreFieldType, "bytes_hash", verify); genreFieldType = new NumberFieldMapper.NumberFieldType(NumberFieldMapper.NumberType.LONG); genreFieldType.setName("genre_id"); testCase(indexSearcher, genreFieldType, null, verify); // wrong field: genreFieldType = new KeywordFieldMapper.KeywordFieldType(); genreFieldType.setName("wrong_field"); genreFieldType.setHasDocValues(true); testCase(indexSearcher, genreFieldType, null, result -> { Terms terms = result.getAggregations().get("terms"); assertEquals(1, terms.getBuckets().size()); assertEquals("0805080481", terms.getBuckets().get(0).getKeyAsString()); }); indexReader.close(); directory.close(); }