field = new SortedSetDocValuesField( key, new BytesRef( value.toString() ) );
/** * Create a query for matching an exact {@link BytesRef} value. * <p>This query also works with fields that have indexed * {@link SortedDocValuesField}s. * <p><b>NOTE</b>: Such queries cannot efficiently advance to the next match, * which makes them slow if they are not ANDed with a selective query. As a * consequence, they are best used wrapped in an {@link IndexOrDocValuesQuery}, * alongside a range query that executes on points, such as * {@link BinaryPoint#newExactQuery}. */ public static Query newSlowExactQuery(String field, BytesRef value) { return newSlowRangeQuery(field, value, value, true, true); } }
@Test public void testSerializationOfSortedSetDocValuesField() throws Exception { Document document = new Document(); document.add( new SortedSetDocValuesField( "foo", new BytesRef( "hello" ) ) ); document.add( new SortedSetDocValuesField( "foo", new BytesRef( "world" ) ) ); List<LuceneWork> expectedWorkList = buildLuceneWorks( document ); serializeDeserializeAndAssert( expectedWorkList ); }
private void processSSDVFacetFields(Map<String,List<SortedSetDocValuesFacetField>> byField, Document doc) throws IOException { //System.out.println("process SSDV: " + byField); for(Map.Entry<String,List<SortedSetDocValuesFacetField>> ent : byField.entrySet()) { String indexFieldName = ent.getKey(); //System.out.println(" field=" + indexFieldName); for(SortedSetDocValuesFacetField facetField : ent.getValue()) { FacetLabel cp = new FacetLabel(facetField.dim, facetField.label); String fullPath = pathToString(cp.components, cp.length); //System.out.println("add " + fullPath); // For facet counts: doc.add(new SortedSetDocValuesField(indexFieldName, new BytesRef(fullPath))); // For drill-down: doc.add(new StringField(indexFieldName, fullPath, Field.Store.NO)); doc.add(new StringField(indexFieldName, facetField.dim, Field.Store.NO)); } } }
private Document buildDocument(BytesRef text, Set<BytesRef> contexts, long weight, BytesRef payload) throws IOException { String textString = text.utf8ToString(); Document doc = new Document(); FieldType ft = getTextFieldType(); doc.add(new Field(TEXT_FIELD_NAME, textString, ft)); doc.add(new Field("textgrams", textString, ft)); doc.add(new StringField(EXACT_TEXT_FIELD_NAME, textString, Field.Store.NO)); doc.add(new BinaryDocValuesField(TEXT_FIELD_NAME, text)); doc.add(new NumericDocValuesField("weight", weight)); if (payload != null) { doc.add(new BinaryDocValuesField("payloads", payload)); } if (contexts != null) { for(BytesRef context : contexts) { doc.add(new StringField(CONTEXTS_FIELD_NAME, context, Field.Store.NO)); doc.add(new SortedSetDocValuesField(CONTEXTS_FIELD_NAME, context)); } } return doc; }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return SortedSetDocValuesField.newRangeQuery(resolveField(queryContext.getFieldMap()), new BytesRef(lower_value), new BytesRef(upper_value), lowerInclusive, upperInclusive); } }
@Override public Query getQuery(final QueryContext queryContext) throws IOException { return SortedSetDocValuesField.newExactQuery(resolveField(queryContext.getFieldMap()), new BytesRef(value)); } }
private List<LuceneWork> buildV12Works() throws Exception { List<LuceneWork> works = new ArrayList<>(); Document document = new Document(); document.add( new NumericDocValuesField( "foo", 22L ) ); document.add( new BinaryDocValuesField( "foo", new BytesRef( "world" ) ) ); document.add( new SortedSetDocValuesField( "foo", new BytesRef( "hello" ) ) ); document.add( new SortedDocValuesField( "foo", new BytesRef( "world" ) ) ); works.add( new AddLuceneWork( 123, "123", remoteTypeId, document ) ); return works; }
@Override protected void onExecute(Document doc, XsObject root, XsObject current, LogicletContext ctx, ExecuteWatcher watcher) { String field = PropertiesConstants.transform(ctx, $field, ""); String value = PropertiesConstants.transform(ctx, $value, ""); if (StringUtils.isNotEmpty(field) && StringUtils.isNotEmpty(value)){ if (sorted){ doc.add(new SortedSetDocValuesField(field,new BytesRef(value))); if (store){ doc.add(new StringField(field,value,Field.Store.YES)); } }else{ doc.add(new StringField(field,value,store?Field.Store.YES:Field.Store.NO)); } } }
@Test public void testSerializationOfMultipleDocValuesFields() throws Exception { Document document = new Document(); document.add( new NumericDocValuesField( "foo", 22L ) ); document.add( new BinaryDocValuesField( "foo", new BytesRef( "world" ) ) ); document.add( new SortedSetDocValuesField( "foo", new BytesRef( "hello" ) ) ); document.add( new SortedSetDocValuesField( "foo", new BytesRef( "world" ) ) ); document.add( new SortedDocValuesField( "foo", new BytesRef( "world" ) ) ); List<LuceneWork> expectedWorkList = buildLuceneWorks( document ); serializeDeserializeAndAssert( expectedWorkList ); }
private void processSSDVFacetFields(Map<String,List<SortedSetDocValuesFacetField>> byField, Document doc) throws IOException { //System.out.println("process SSDV: " + byField); for(Map.Entry<String,List<SortedSetDocValuesFacetField>> ent : byField.entrySet()) { String indexFieldName = ent.getKey(); //System.out.println(" field=" + indexFieldName); for(SortedSetDocValuesFacetField facetField : ent.getValue()) { FacetLabel cp = new FacetLabel(facetField.dim, facetField.label); String fullPath = pathToString(cp.components, cp.length); //System.out.println("add " + fullPath); // For facet counts: doc.add(new SortedSetDocValuesField(indexFieldName, new BytesRef(fullPath))); // For drill-down: doc.add(new StringField(indexFieldName, fullPath, Field.Store.NO)); FacetsConfig.DimConfig ft = getDimConfig(facetField.dim); if (ft.requireDimensionDrillDown) { doc.add(new StringField(indexFieldName, facetField.dim, Field.Store.NO)); } } } }
@Override protected void parseCreateField(ParseContext context, List<IndexableField> fields) throws IOException { if (fieldType().indexOptions() == IndexOptions.NONE && !fieldType().stored()) { return; } fields.add(new Field(fieldType().name(), context.sourceToParse().type(), fieldType())); if (fieldType().hasDocValues()) { fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(context.sourceToParse().type()))); } }
/** * Create a query for matching an exact {@link BytesRef} value. * <p>This query also works with fields that have indexed * {@link SortedDocValuesField}s. * <p><b>NOTE</b>: Such queries cannot efficiently advance to the next match, * which makes them slow if they are not ANDed with a selective query. As a * consequence, they are best used wrapped in an {@link IndexOrDocValuesQuery}, * alongside a range query that executes on points, such as * {@link BinaryPoint#newExactQuery}. */ public static Query newSlowExactQuery(String field, BytesRef value) { return newSlowRangeQuery(field, value, value, true, true); } }
static Document buildDoc(JSONObject json) throws Exception{ Document doc = new Document(); doc.add(new NumericDocValuesField("id", json.getLong("id"))); doc.add(new DoubleDocValuesField("price", json.optDouble("price"))); doc.add(new TextField("contents", json.optString("contents"), Store.NO)); doc.add(new NumericDocValuesField("year", json.optInt("year"))); if (parts.length > 0) { for (String part : parts) { doc.add(new SortedSetDocValuesField("tags", new BytesRef(part))); doc.add(new StringField("tags_indexed", part, Store.NO)); doc.add(new BinaryDocValuesField("json", new BytesRef(json.toString())));
@Override public void addDocValuesFieldWithBinaryData(String name, String type, byte[] value, int offset, int length) { DocValuesType docValuesType = Enum.valueOf( DocValuesType.class, type ); Field docValuesField; switch ( docValuesType ) { // data is ByteRef case BINARY: { docValuesField = new BinaryDocValuesField( name, new BytesRef( value, offset, length ) ); break; } case SORTED: { docValuesField = new SortedDocValuesField( name, new BytesRef( value, offset, length ) ); break; } case SORTED_SET: { docValuesField = new SortedSetDocValuesField( name, new BytesRef( value, offset, length ) ); break; } default: { // in case Lucene is going to add more in coming releases throw log.unexpectedBinaryDocValuesTypeType( type ); } } getLuceneDocument().add( docValuesField ); }
final BytesRef binaryValue = new BytesRef(value); if (fieldType().indexOptions() != IndexOptions.NONE || fieldType().stored()) { Field field = new Field(fieldType().name(), binaryValue, fieldType()); fields.add(new SortedSetDocValuesField(fieldType().name(), binaryValue));
private static void addDoc(IndexWriter w, String title, String uid) throws IOException { Document doc = new Document(); doc.add(new TextField("title", title, Field.Store.YES)); doc.add(new TextField("uid", uid, Field.Store.YES)); doc.add(new StringField("uid", uid, Field.Store.YES)); doc.add(new IntPoint("testIntField", 3)); long date = System.currentTimeMillis(); doc.add(new LongPoint("date", date)); doc.add(new NumericDocValuesField("date", date)); doc.add(new SortedSetDocValuesField("category", new BytesRef("Anything"))); Term uidTerm = new Term("uid", uid); w.updateDocument(uidTerm, doc); }
@Override public void addDocValuesFieldWithBinaryData(String name, String type, byte[] value, int offset, int length) { DocValuesType docValuesType = Enum.valueOf( DocValuesType.class, type ); Field docValuesField; switch ( docValuesType ) { // data is ByteRef case BINARY: { docValuesField = new BinaryDocValuesField( name, new BytesRef( value, offset, length ) ); break; } case SORTED: { docValuesField = new SortedDocValuesField( name, new BytesRef( value, offset, length ) ); break; } case SORTED_SET: { docValuesField = new SortedSetDocValuesField( name, new BytesRef( value, offset, length ) ); break; } default: { // in case Lucene is going to add more in coming releases throw log.unexpectedBinaryDocValuesTypeType( type ); } } getLuceneDocument().add( docValuesField ); }
fields.add(new SortedSetDocValuesField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address)))); } else if (fieldType().stored() || fieldType().indexOptions() != IndexOptions.NONE) { createFieldNamesField(context, fields); fields.add(new StoredField(fieldType().name(), new BytesRef(InetAddressPoint.encode(address))));
d.add(docValue); d.add(docValue); if (obj instanceof Boolean) { String text = obj.toString(); SortedSetDocValuesField docValue = new SortedSetDocValuesField(sortFieldName, new BytesRef(text)); d.add(docValue); SortedSetDocValuesField docValue = new SortedSetDocValuesField(sortFieldName, new BytesRef(text)); d.add(docValue); });