Example usage for org.apache.solr.common SolrInputField getValues

List of usage examples for org.apache.solr.common SolrInputField getValues

Introduction

In this page you can find the example usage for org.apache.solr.common SolrInputField getValues.

Prototype

@SuppressWarnings("unchecked")
public Collection<Object> getValues() 

Source Link

Usage

From source file:com.francelabs.datafari.updateprocessor.DatafariUpdateProcessor.java

License:Apache License

private String extensionFromMimeTypeField(SolrInputField mimeTypeField) {
    String extension = "";
    String[] mimeTypeList = mimeTypeField.getValues().toArray(new String[0]);
    for (String mimeType : mimeTypeList) {
        if (mimeType.contains(";")) {
            final String[] parts = mimeType.split(";");
            mimeType = parts[0];//from   w  ww. java 2  s.com
        }
        final MimeTypes allTypes = MimeTypes.getDefaultMimeTypes();
        MimeType type;

        try {
            type = allTypes.forName(mimeType);
            String currentExtension = type.getExtension();
            if (currentExtension.length() > 1) {
                currentExtension = currentExtension.substring(1);
            }
            if (!currentExtension.equals("bin")) {
                extension = currentExtension;
            }
        } catch (final MimeTypeException e) {
        }
    }
    return extension;
}

From source file:com.ngdata.hbaseindexer.indexer.FusionDocumentWriter.java

License:Apache License

protected void appendField(SolrInputDocument doc, String f, String pfx, List fields) {
    SolrInputField field = doc.getField(f);
    int vc = field.getValueCount();
    if (vc <= 0)
        return; // no values to add for this field

    if (vc == 1) {
        Map<String, Object> fieldMap = mapField(f, pfx, field.getFirstValue());
        if (fieldMap != null)
            fields.add(fieldMap);/*from w  w w. j av a2  s .c o  m*/
    } else {
        for (Object val : field.getValues()) {
            Map<String, Object> fieldMap = mapField(f, pfx, val);
            if (fieldMap != null)
                fields.add(fieldMap);
        }
    }
}

From source file:com.ngdata.hbaseindexer.parse.DefaultResultToSolrMapperTest.java

License:Apache License

@Test
public void testMap() {
    FieldDefinition fieldDefA = new FieldDefinition("fieldA", "cfA:qualifierA", ValueSource.VALUE, "int");
    FieldDefinition fieldDefB = new FieldDefinition("fieldB", "cfB:qualifierB", ValueSource.VALUE,
            DummyValueMapper.class.getName());
    DefaultResultToSolrMapper resultMapper = new DefaultResultToSolrMapper("index-name",
            Lists.newArrayList(fieldDefA, fieldDefB), Collections.<DocumentExtractDefinition>emptyList());

    KeyValue kvA = new KeyValue(ROW, COLUMN_FAMILY_A, QUALIFIER_A, Bytes.toBytes(42));
    KeyValue kvB = new KeyValue(ROW, COLUMN_FAMILY_B, QUALIFIER_B, Bytes.toBytes("dummy value"));
    Result result = newResult(Lists.newArrayList(kvA, kvB));

    resultMapper.map(result, solrUpdateWriter);
    verify(solrUpdateWriter).add(solrInputDocCaptor.capture());

    SolrInputDocument solrDocument = solrInputDocCaptor.getValue();

    assertEquals(Sets.newHashSet("fieldA", "fieldB"), solrDocument.keySet());

    SolrInputField fieldA = solrDocument.get("fieldA");
    SolrInputField fieldB = solrDocument.get("fieldB");

    assertEquals(Lists.newArrayList(42), fieldA.getValues());
    assertEquals(Lists.newArrayList("A", "B", "C"), fieldB.getValues());
}

From source file:com.ngdata.hbaseindexer.parse.SolrInputDocumentBuilder.java

License:Apache License

/**
 * Merge a {@code SolrInputDocument} into the master document, adding a prefix to every field name as it is added.
 * // ww w.j  av a 2 s .c o m
 * @param inputDocument document to be added
 * @param prefix prefix to be added to field names
 */
public void add(SolrInputDocument inputDocument, String prefix) {
    for (Entry<String, SolrInputField> entry : inputDocument.entrySet()) {
        SolrInputField inputField = entry.getValue();
        document.addField(prefix + entry.getKey(), inputField.getValues(), inputField.getBoost());
    }
}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void getDocumentAddsLiteralFieldsForMultipleValuesOfSamePredicate() {

    ArrayList<Quad> quads = new ArrayList<Quad>();
    int NUMBER_OF_QUADS = 10;
    for (int i = 0; i < NUMBER_OF_QUADS; i++) {
        quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI),
                Node.createURI(PREDICATE_BASE), Node.createLiteral(OBJECT_BASE + i)));
    }/* w w  w  .ja  va 2  s. c  o m*/

    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);
    assertNotNull(doc);

    SolrInputField field = doc.getField(PREDICATE_BASE);
    assertEquals(NUMBER_OF_QUADS, field.getValueCount());
    Collection<Object> values = field.getValues();
    for (int i = 0; i < NUMBER_OF_QUADS; i++) {
        String expected = OBJECT_BASE + i;
        assertTrue(values.contains(expected));
    }

}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void statisticsFieldsForPropertiesAreAddedToDocument() {
    String firstPredicate = PREDICATE_BASE + "first";
    String secondPredicate = PREDICATE_BASE + "second";
    ArrayList<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(firstPredicate),
            Node.createURI("http://example.com/resources/0")));
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(secondPredicate),
            Node.createURI("http://example.com/resources/1")));

    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);

    SolrInputField propertyField = doc.getField(FieldNames.PROPERTY);
    assertTrue(propertyField.getValues().contains(firstPredicate));
    assertTrue(propertyField.getValues().contains(secondPredicate));
    assertEquals(2, propertyField.getValues().size());

    SolrInputField namespaceField = doc.getField(FieldNames.PROPERTY_NS);
    assertTrue(namespaceField.getValues().contains(PREDICATE_BASE));
    assertEquals(2, namespaceField.getValues().size());
}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void addNamespaceFieldsForNonXmlCompliantPredicateUris() {
    String firstPredicate = PREDICATE_BASE + "0";
    String secondPredicate = PREDICATE_BASE + "1";
    ArrayList<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(firstPredicate),
            Node.createURI("http://example.com/resources/0")));
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(secondPredicate),
            Node.createURI("http://example.com/resources/1")));

    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);

    SolrInputField propertyField = doc.getField(FieldNames.PROPERTY);
    assertTrue(propertyField.getValues().contains(firstPredicate));
    assertTrue(propertyField.getValues().contains(secondPredicate));
    assertEquals(2, propertyField.getValues().size());

    SolrInputField namespaceField = doc.getField(FieldNames.PROPERTY_NS);
    assertTrue(namespaceField.getValues().contains(firstPredicate));
    assertTrue(namespaceField.getValues().contains(secondPredicate));
    assertEquals(2, namespaceField.getValues().size());
}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void statisticsFieldsForClassesAreAddedToDocument() {
    String firstClass = PREDICATE_BASE + "first";
    String secondClass = PREDICATE_BASE + "second";
    ArrayList<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI),
            Node.createURI(RDF.type.getURI()), Node.createURI(firstClass)));
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI),
            Node.createURI(RDF.type.getURI()), Node.createURI(secondClass)));

    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);

    SolrInputField propertyField = doc.getField(FieldNames.CLASS);
    assertTrue(propertyField.getValues().contains(firstClass));
    assertTrue(propertyField.getValues().contains(secondClass));
    assertEquals(2, propertyField.getValues().size());

    SolrInputField namespaceField = doc.getField(FieldNames.CLASS_NS);
    assertTrue(namespaceField.getValues().contains(PREDICATE_BASE));
    assertEquals(2, namespaceField.getValues().size());
}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void addNamespaceFieldsForNonXmlCompliantClassUris() {
    String firstClass = PREDICATE_BASE + "0";
    String secondClass = PREDICATE_BASE + "1";
    ArrayList<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI),
            Node.createURI(RDF.type.getURI()), Node.createURI(firstClass)));
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI),
            Node.createURI(RDF.type.getURI()), Node.createURI(secondClass)));

    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);

    SolrInputField propertyField = doc.getField(FieldNames.CLASS);
    assertTrue(propertyField.getValues().contains(firstClass));
    assertTrue(propertyField.getValues().contains(secondClass));
    assertEquals(2, propertyField.getValues().size());

    SolrInputField namespaceField = doc.getField(FieldNames.CLASS_NS);
    assertTrue(namespaceField.getValues().contains(firstClass));
    assertTrue(namespaceField.getValues().contains(secondClass));
    assertEquals(2, namespaceField.getValues().size());
}

From source file:com.talis.rdf.solr.DefaultDocumentBuilderTest.java

License:Apache License

@Test
public void literalValuesAreIndexedByPredicateUri() {
    String predicateURI = PREDICATE_BASE + "first";
    ArrayList<Quad> quads = new ArrayList<Quad>();
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(predicateURI),
            Node.createURI("http://example.com/resource")));
    quads.add(new Quad(Node.createURI(GRAPH_URI), Node.createURI(SUBJECT_URI), Node.createURI(predicateURI),
            Node.createLiteral("Aloha")));
    SolrInputDocument doc = quadsToDoc.getDocument(DOCUMENT_KEY, quads);
    SolrInputField field = doc.getField(predicateURI);
    assertEquals("Aloha", field.getFirstValue());
    assertEquals(1, field.getValues().size());
}