Package org.apache.solr.common

Examples of org.apache.solr.common.SolrInputField


                }
            }
            if(fieldBoost != null){ //we need still to do part (2) of setting the correct boost
                for(Entry<String,int[]> entry : fieldsToBoost.entrySet()){
                    if(entry.getValue()[0] > 1) { //adapt the boost only for multi valued fields
                        SolrInputField solrField = inputDocument.getField(entry.getKey());
                        //the correct bosst is baseBoost (representing entity boost with field
                        //boost) multiplied with the sqrt(fieldValues). The 2nd part aims to
                        //compensate the Solr lengthNorm (1/sqrt(fieldTokens))
                        //see STANBOL-1027 for details
                        solrField.setBoost(baseBoost*(float)Math.sqrt(entry.getValue()[0]));
                    }
                }
            }
        }
        return inputDocument;
View Full Code Here


    for (SolrInputDocument document : docs) {
      updateUnmarshalled.add(document);
    }

    SolrInputDocument outDoc = updateUnmarshalled.getDocuments().get(0);
    SolrInputField iter = outDoc.getField("iter");
    Assert.assertNotNull("iter field is null", iter);
    Object iterVal = iter.getValue();
    Assert.assertTrue("iterVal is not a Collection",
                      iterVal instanceof Collection);
    Assert.assertEquals("iterVal contents", values, iterVal);

  }
View Full Code Here

                           SolrInputDocument actualDoc) {
    Assert.assertEquals(expectedDoc.getDocumentBoost(),
                        actualDoc.getDocumentBoost());

    for (String s : expectedDoc.getFieldNames()) {
      SolrInputField expectedField = expectedDoc.getField(s);
      SolrInputField actualField = actualDoc.getField(s);
      Assert.assertEquals(m + ": diff boosts for field: " + s,
                          expectedField.getBoost(), actualField.getBoost());
      Object expectedVal = expectedField.getValue();
      Object actualVal = actualField.getValue();
      if (expectedVal instanceof Set &&
          actualVal instanceof Collection) {
        // unmarshaled documents never contain Sets, they are just a
        // List in an arbitrary order based on what the iterator of
        // hte original Set returned, so we need a comparison that is
View Full Code Here

    public void testAdd_IdAlreadyPresent() {
        IdAddingSolrUpdateWriter updateWriter = new IdAddingSolrUpdateWriter(
                UNIQUE_KEY_FIELD, DOCUMENT_ID, null, TABLE_NAME, updateCollector);
       
       
        SolrInputField solrIdField = new SolrInputField(DOCUMENT_ID);
        solrIdField.setValue(DOCUMENT_ID, 1.0f);
       
        when(solrDoc.getField(UNIQUE_KEY_FIELD)).thenReturn(solrIdField);

        updateWriter.add(solrDoc);
View Full Code Here

                UNIQUE_KEY_FIELD, DOCUMENT_ID, null, TABLE_NAME, updateCollector);
       
        SolrInputDocument docA = mock(SolrInputDocument.class);
        SolrInputDocument docB = mock(SolrInputDocument.class);
       
        SolrInputField keyFieldA = new SolrInputField(UNIQUE_KEY_FIELD);
        keyFieldA.setValue(idA, 1.0f);
        SolrInputField keyFieldB = new SolrInputField(UNIQUE_KEY_FIELD);
        keyFieldB.setValue(idB, 1.0f);
       
       
        when(docA.getField(UNIQUE_KEY_FIELD)).thenReturn(keyFieldA);
        when(docB.getField(UNIQUE_KEY_FIELD)).thenReturn(keyFieldB);
View Full Code Here

     * @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());
        }
    }
View Full Code Here

       
        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());
    }
View Full Code Here

     * Adding multiple documents without ids will result in an IllegalStateException being thrown.
     */
    @Override
    public void add(SolrInputDocument solrDocument) {
        String docId = documentId;
        SolrInputField uniqueKeySolrField = solrDocument.getField(uniqueKeyField);
        if (uniqueKeySolrField == null) {
            if (idUsed) {
                throw new IllegalStateException("Document id '" + documentId + "' has already been used by this record");
            }
            solrDocument.addField(uniqueKeyField, documentId);
            idUsed = true;
        } else {
            docId = uniqueKeySolrField.getValue().toString();
        }
       
        if (tableNameField != null) {
            solrDocument.addField(tableNameField, tableName);
        }
View Full Code Here

          Class<?> rawMapType = mapTypeInformation.getType();

          Map<?, ?> map = (Map<?, ?>) fieldValue;
          for (Map.Entry<?, ?> entry : map.entrySet()) {
            String mappedFieldName = entry.getKey().toString();
            SolrInputField field = new SolrInputField(mappedFieldName);
            if (entry.getValue() instanceof Iterable) {
              for (Object o : (Iterable<?>) entry.getValue()) {
                field.addValue(convertToSolrType(rawMapType, o), 1f);
              }
            } else {
              if (rawMapType.isArray()) {
                for (Object o : (Object[]) entry.getValue()) {
                  field.addValue(convertToSolrType(rawMapType, o), 1f);
                }
              } else {
                field.addValue(convertToSolrType(rawMapType, entry.getValue()), 1f);
              }
            }
            target.put(mappedFieldName, field);
          }
          return;
        }

        SolrInputField field = new SolrInputField(persistentProperty.getFieldName());
        if (persistentProperty.isCollectionLike()) {
          Collection<?> collection = asCollection(fieldValue);
          for (Object o : collection) {
            if (o != null) {
              field.addValue(convertToSolrType(persistentProperty.getType(), o), 1f);
            }
          }
        } else {
          field.setValue(convertToSolrType(persistentProperty.getType(), fieldValue), 1f);
        }
        target.put(persistentProperty.getFieldName(), field);

        if (persistentProperty.isBoosted()) {
          field.setBoost(persistentProperty.getBoost());
        }

      }
    });
View Full Code Here

    this.fieldName = fieldName;
  }

  @Override
  public int compare(SolrInputDocument doc1, SolrInputDocument doc2) {
    SolrInputField f1 = doc1.getField(fieldName);
    SolrInputField f2 = doc2.getField(fieldName);
    if (f1 == f2) {
      return 0;
    } else if (f1 == null) {
      return -1;
    } else if (f2 == null) {
      return 1;
    }
   
    Object v1 = f1.getFirstValue();
    Object v2 = f2.getFirstValue();         
    return child.compare(v1, v2);
  }
View Full Code Here

TOP

Related Classes of org.apache.solr.common.SolrInputField

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.