org.apache.solr.schema.SchemaField Java Examples

The following examples show how to use org.apache.solr.schema.SchemaField. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: UniqueAgg.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
  SchemaField sf = fcontext.qcontext.searcher().getSchema().getField(getArg());
  if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
    if (sf.getType().isPointField()) {
      return new SortedNumericAcc(fcontext, getArg(), numSlots);
    } else if (sf.hasDocValues()) {
      return new UniqueMultiDvSlotAcc(fcontext, sf, numSlots, null);
    } else {
      return new UniqueMultivaluedSlotAcc(fcontext, sf, numSlots, null);
    }
  } else {
    if (sf.getType().getNumberType() != null) {
      return new NumericAcc(fcontext, getArg(), numSlots);
    } else {
      return new UniqueSinglevaluedSlotAcc(fcontext, sf, numSlots, null);
    }
  }
}
 
Example #2
Source File: AlfrescoLukeRequestHandler.java    From SearchServices with GNU Lesser General Public License v3.0 6 votes vote down vote up
/**
 * This is a destructive call... the queue is empty at the end
 */
public NamedList<Integer> toNamedList(IndexSchema schema) {
	// reverse the list..
	List<TermInfo> aslist = new LinkedList<>();
	while (size() > 0) {
		aslist.add(0, (TermInfo) pop());
	}

	NamedList<Integer> list = new NamedList<>();
	for (TermInfo i : aslist) {
		String txt = i.term.text();
		SchemaField ft = schema.getFieldOrNull(i.term.field());
		if (ft != null) {
			txt = ft.getType().indexedToReadable(txt);
		}
		list.add(txt, i.docFreq);
	}
	return list;
}
 
Example #3
Source File: GeoDistValueSourceParser.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private MultiValueSource parseSfield(FunctionQParser fp) throws SyntaxError {
  String sfield = fp.getParam(SpatialParams.FIELD);
  if (sfield == null) return null;
  SchemaField sf = fp.getReq().getSchema().getField(sfield);
  FieldType type = sf.getType();
  if (type instanceof AbstractSpatialFieldType) {
    @SuppressWarnings({"rawtypes"})
    AbstractSpatialFieldType asft = (AbstractSpatialFieldType) type;
    return new SpatialStrategyMultiValueSource(asft.getStrategy(sfield), asft.getDistanceUnits());
  }
  ValueSource vs = type.getValueSource(sf, fp);
  if (vs instanceof MultiValueSource) {
    return (MultiValueSource)vs;
  }
  throw new SyntaxError("Spatial field must implement MultiValueSource or extend AbstractSpatialFieldType:" + sf);
}
 
Example #4
Source File: SecureRealTimeGetComponent.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
/**
 * @param doc SolrDocument to check
 * @param idField field where the id is stored
 * @param fieldType type of id field
 * @param filterQuery Query to filter by
 * @param searcher SolrIndexSearcher on which to apply the filter query
 * @returns the internal docid, or -1 if doc is not found or doesn't match filter
 */
private static int getFilteredInternalDocId(SolrDocument doc, SchemaField idField, FieldType fieldType,
      Query filterQuery, SolrIndexSearcher searcher) throws IOException {
  int docid = -1;
  Field f = (Field)doc.getFieldValue(idField.getName());
  String idStr = f.stringValue();
  BytesRef idBytes = new BytesRef();
  fieldType.readableToIndexed(idStr, idBytes);
  // get the internal document id
  long segAndId = searcher.lookupId(idBytes);

    // if docid is valid, run it through the filter
  if (segAndId >= 0) {
    int segid = (int) segAndId;
    AtomicReaderContext ctx = searcher.getTopReaderContext().leaves().get((int) (segAndId >> 32));
    docid = segid + ctx.docBase;
    Weight weight = filterQuery.createWeight(searcher);
    Scorer scorer = weight.scorer(ctx, null);
    if (scorer == null || segid != scorer.advance(segid)) {
      // filter doesn't match.
      docid = -1;
    }
  }
  return docid;
}
 
Example #5
Source File: SolrIndexSearcher.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Returns a weighted sort spec according to this searcher */
private SortSpec implWeightSortSpec(Sort originalSort, int num, int offset, Sort nullEquivalent) throws IOException {
  Sort rewrittenSort = weightSort(originalSort);
  if (rewrittenSort == null) {
    rewrittenSort = nullEquivalent;
  }

  final SortField[] rewrittenSortFields = rewrittenSort.getSort();
  final SchemaField[] rewrittenSchemaFields = new SchemaField[rewrittenSortFields.length];
  for (int ii = 0; ii < rewrittenSortFields.length; ++ii) {
    final String fieldName = rewrittenSortFields[ii].getField();
    rewrittenSchemaFields[ii] = (fieldName == null ? null : schema.getFieldOrNull(fieldName));
  }

  return new SortSpec(rewrittenSort, rewrittenSchemaFields, num, offset);
}
 
Example #6
Source File: SearchGroupsResultTransformer.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@SuppressWarnings({"rawtypes"})
private SearchGroup<BytesRef> deserializeOneSearchGroup(SchemaField groupField, String groupValue,
    SortField[] groupSortField, List<Comparable> rawSearchGroupData) {
  SearchGroup<BytesRef> searchGroup = new SearchGroup<>();
  searchGroup.groupValue = null;
  if (groupValue != null) {
    if (groupField != null) {
      BytesRefBuilder builder = new BytesRefBuilder();
      groupField.getType().readableToIndexed(groupValue, builder);
      searchGroup.groupValue = builder.get();
    } else {
      searchGroup.groupValue = new BytesRef(groupValue);
    }
  }
  searchGroup.sortValues = rawSearchGroupData.toArray(new Comparable[rawSearchGroupData.size()]);
  for (int i = 0; i < searchGroup.sortValues.length; i++) {
    SchemaField field = groupSortField[i].getField() != null ? searcher.getSchema().getFieldOrNull(groupSortField[i].getField()) : null;
    searchGroup.sortValues[i] = ShardResultTransformerUtils.unmarshalSortValue(searchGroup.sortValues[i], field);
  }
  return searchGroup;
}
 
Example #7
Source File: RangeFacet.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void createFacetValueExecuters(final Filter filter, SolrQueryRequest queryRequest, Consumer<FacetValueQueryExecuter> consumer) {
  // Computes the end points of the ranges in the rangeFacet
  final FacetRangeGenerator<? extends Comparable<?>> rec = FacetRangeGenerator.create(this);
  final SchemaField sf = field;

  // Create a rangeFacetAccumulator for each range and
  // collect the documents for that range.
  for (FacetRange range : rec.getRanges()) {
    Query q = sf.getType().getRangeQuery(null, sf, range.lower, range.upper, range.includeLower,range.includeUpper);
    // The searcher sends docIds to the RangeFacetAccumulator which forwards
    // them to <code>collectRange()</code> in this class for collection.
    Query rangeQuery = QueryUtils.combineQueryAndFilter(q, filter);

    ReductionDataCollection dataCol = collectionManager.newDataCollection();
    reductionData.put(range.toString(), dataCol);
    consumer.accept(new FacetValueQueryExecuter(dataCol, rangeQuery));
  }
}
 
Example #8
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
  * @param existsRequested facet.exists=true is passed for the given field
  * */
static FacetMethod selectFacetMethod(String fieldName, 
                                     SchemaField field, FacetMethod method, Integer mincount,
                                     boolean existsRequested) {
  if (existsRequested) {
    checkMincountOnExists(fieldName, mincount);
    if (method == null) {
      method = FacetMethod.ENUM;
    }
  }
  final FacetMethod facetMethod = selectFacetMethod(field, method, mincount);
  
  if (existsRequested && facetMethod!=FacetMethod.ENUM) {
    throw new SolrException (ErrorCode.BAD_REQUEST, 
        FacetParams.FACET_EXISTS + "=true is requested, but "+
        FacetParams.FACET_METHOD+"="+FacetParams.FACET_METHOD_enum+ " can't be used with "+fieldName
    );
  }
  return facetMethod;
}
 
Example #9
Source File: UnifiedSolrHighlighter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Retrieves the unique keys for the topdocs to key the results
 */
protected String[] getUniqueKeys(SolrIndexSearcher searcher, int[] docIDs) throws IOException {
  IndexSchema schema = searcher.getSchema();
  SchemaField keyField = schema.getUniqueKeyField();
  if (keyField != null) {
    SolrReturnFields returnFields = new SolrReturnFields(keyField.getName(), null);
    String[] uniqueKeys = new String[docIDs.length];
    for (int i = 0; i < docIDs.length; i++) {
      int docid = docIDs[i];
      SolrDocument solrDoc = searcher.getDocFetcher().solrDoc(docid, returnFields);
      uniqueKeys[i] = schema.printableUniqueKey(solrDoc);
    }
    return uniqueKeys;
  } else {
    return new String[docIDs.length];
  }
}
 
Example #10
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Collector getInsanityWrapper(final String field, Collector collector) {
  SchemaField sf = searcher.getSchema().getFieldOrNull(field);
  if (sf != null && !sf.hasDocValues() && !sf.multiValued() && sf.getType().getNumberType() != null) {
    // it's a single-valued numeric field: we must currently create insanity :(
    // there isn't a GroupedFacetCollector that works on numerics right now...
    return new FilterCollector(collector) {
      @Override
      public LeafCollector getLeafCollector(LeafReaderContext context) throws IOException {
        LeafReader insane = Insanity.wrapInsanity(context.reader(), field);
        return in.getLeafCollector(insane.getContext());
      }
    };
  } else {
    return collector;
  }
}
 
Example #11
Source File: SolrDocumentFetcher.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/**
 * Returns a collection of the names of all stored fields which can be highlighted the index reader knows about.
 */
public Collection<String> getStoredHighlightFieldNames() {
  synchronized (this) {
    if (storedHighlightFieldNames == null) {
      storedHighlightFieldNames = new LinkedList<>();
      for (FieldInfo fieldInfo : searcher.getFieldInfos()) {
        final String fieldName = fieldInfo.name;
        try {
          SchemaField field = searcher.getSchema().getField(fieldName);
          if (field.stored() && ((field.getType() instanceof org.apache.solr.schema.TextField)
              || (field.getType() instanceof org.apache.solr.schema.StrField))) {
            storedHighlightFieldNames.add(fieldName);
          }
        } catch (RuntimeException e) { // getField() throws a SolrException, but it arrives as a RuntimeException
          log.warn("Field [{}] found in index, but not defined in schema.", fieldName);
        }
      }
    }
    return storedHighlightFieldNames;
  }
}
 
Example #12
Source File: TestFacetMethods.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testStringSingleValuedDV() {

  for (int props : Arrays.asList(DOC_VALUES ^ UNINVERTIBLE,
                                 DOC_VALUES)) {
    SchemaField field = new SchemaField("field", new StrField(), props, null);
    // default is FC, otherwise just uses the passed-in method as is unless UIF...
    for (int mincount : Arrays.asList(0, 1)) {
      // behavior should be independent of mincount
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, mincount));
      assertEquals(FacetMethod.ENUM, SimpleFacets.selectFacetMethod(field, FacetMethod.ENUM, mincount));
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, FacetMethod.FC, mincount));
      assertEquals(FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, FacetMethod.FCS, mincount));
      // UIF only allowed if field is UNINVERTIBLE
      assertEquals(propsMatch(props, UNINVERTIBLE) ? FacetMethod.UIF : FacetMethod.FCS,
                   SimpleFacets.selectFacetMethod(field, FacetMethod.UIF, mincount));
    }
  }
}
 
Example #13
Source File: GroupConverter.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
static Collection<SearchGroup<BytesRef>> fromMutable(SchemaField field, Collection<SearchGroup<MutableValue>> values) {
  if (values == null) {
    return null;
  }
  FieldType fieldType = field.getType();
  List<SearchGroup<BytesRef>> result = new ArrayList<>(values.size());
  for (SearchGroup<MutableValue> original : values) {
    SearchGroup<BytesRef> converted = new SearchGroup<>();
    converted.sortValues = original.sortValues;
    if (original.groupValue.exists) {
      BytesRefBuilder binary = new BytesRefBuilder();
      fieldType.readableToIndexed(Utils.OBJECT_TO_STRING.apply(original.groupValue.toObject()), binary);
      converted.groupValue = binary.get();
    } else {
      converted.groupValue = null;
    }
    result.add(converted);
  }
  return result;
}
 
Example #14
Source File: AddUpdateCommand.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
/** Returns the indexed ID for this document.  The returned BytesRef is retained across multiple calls, and should not be modified. */
public BytesRef getIndexedId() {
  if (indexedId == null) {
    IndexSchema schema = req.getSchema();
    SchemaField sf = schema.getUniqueKeyField();
    if (sf != null) {
      if (solrDoc != null) {
        SolrInputField field = solrDoc.getField(sf.getName());

        int count = field==null ? 0 : field.getValueCount();
        if (count == 0) {
          if (overwrite) {
            throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document is missing mandatory uniqueKey field: " + sf.getName());
          }
        } else if (count  > 1) {
          throw new SolrException( SolrException.ErrorCode.BAD_REQUEST,"Document contains multiple values for uniqueKey field: " + field);
        } else {
          BytesRefBuilder b = new BytesRefBuilder();
          sf.getType().readableToIndexed(field.getFirstValue().toString(), b);
          indexedId = b.get();
        }
      }
    }
  }
  return indexedId;
}
 
Example #15
Source File: TestFacetMethods.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testNumericMultiValuedNoDV() {

  for (int props : Arrays.asList(MULTIVALUED ^ UNINVERTIBLE,
                                 MULTIVALUED)) {
    SchemaField field = new SchemaField("field", new TrieIntField(), props, null);
    // FC is used by default for most requested methods other then UIF -- regardless of mincount
    for (int mincount : Arrays.asList(0, 1)) {
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, null, mincount));
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, FacetMethod.ENUM, mincount));
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, FacetMethod.FC, mincount));
      assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, FacetMethod.FCS, mincount));
    }
    // UIF allowed only if UNINVERTIBLE *AND* mincount > 0
    assertEquals(FacetMethod.FC, SimpleFacets.selectFacetMethod(field, FacetMethod.UIF, 0));
    assertEquals(propsMatch(props, UNINVERTIBLE) ? FacetMethod.UIF : FacetMethod.FC,
                 SimpleFacets.selectFacetMethod(field, FacetMethod.UIF, 1));
  }
}
 
Example #16
Source File: DirectUpdateHandler2.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private Query getQuery(DeleteUpdateCommand cmd) {
  Query q;
  try {
    // move this higher in the stack?
    QParser parser = QParser.getParser(cmd.getQuery(), cmd.req);
    q = parser.getQuery();
    q = QueryUtils.makeQueryable(q);

    // Make sure not to delete newer versions
    if (ulog != null && cmd.getVersion() != 0 && cmd.getVersion() != -Long.MAX_VALUE) {
      BooleanQuery.Builder bq = new BooleanQuery.Builder();
      bq.add(q, Occur.MUST);
      SchemaField sf = ulog.getVersionInfo().getVersionField();
      ValueSource vs = sf.getType().getValueSource(sf, null);
      ValueSourceRangeFilter filt = new ValueSourceRangeFilter(vs, Long.toString(Math.abs(cmd.getVersion())), null, true, true);
      FunctionRangeQuery range = new FunctionRangeQuery(filt);
      bq.add(range, Occur.MUST_NOT);  // formulated in the "MUST_NOT" sense so we can delete docs w/o a version (some tests depend on this...)
      q = bq.build();
    }

    return q;

  } catch (SyntaxError e) {
    throw new SolrException(SolrException.ErrorCode.BAD_REQUEST, e);
  }
}
 
Example #17
Source File: SignatureUpdateProcessorFactory.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public void inform(SolrCore core) {
  final SchemaField field = core.getLatestSchema().getFieldOrNull(getSignatureField());
  if (null == field) {
    throw new SolrException
      (ErrorCode.SERVER_ERROR,
       "Can't use signatureField which does not exist in schema: "
       + getSignatureField());
  }

  if (getOverwriteDupes() && ( ! field.indexed() ) ) {
    throw new SolrException
      (ErrorCode.SERVER_ERROR,
       "Can't set overwriteDupes when signatureField is not indexed: "
       + getSignatureField());
  }
}
 
Example #18
Source File: TestFacetMethods.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Test
public void testNumericSingleValuedDV() {

  for (int props : Arrays.asList(DOC_VALUES ^ UNINVERTIBLE,
                                 DOC_VALUES)) {
    SchemaField field = new SchemaField("field", new TrieIntField(), props, null);
    // default is FCS, can't use ENUM due to trie-field terms, FC rewrites to FCS for efficiency
    for (int mincount : Arrays.asList(0, 1)) {
      // behavior should be independent of mincount
      assertEquals(FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, null, mincount));
      assertEquals(FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, FacetMethod.ENUM, mincount));
      assertEquals(FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, FacetMethod.FC, mincount));
      assertEquals(FacetMethod.FCS, SimpleFacets.selectFacetMethod(field, FacetMethod.FCS, mincount));
      
      // UIF only allowed if field is UNINVERTIBLE
      assertEquals(propsMatch(props, UNINVERTIBLE) ? FacetMethod.UIF : FacetMethod.FCS,
                   SimpleFacets.selectFacetMethod(field, FacetMethod.UIF, 0));
    }
  }
}
 
Example #19
Source File: SecureRealTimeGetComponent.java    From incubator-sentry with Apache License 2.0 6 votes vote down vote up
private static SolrDocument toSolrDoc(Document doc, IndexSchema schema) {
  SolrDocument out = new SolrDocument();
  for ( IndexableField f : doc.getFields() ) {
    // Make sure multivalued fields are represented as lists
    Object existing = out.get(f.name());
    if (existing == null) {
      SchemaField sf = schema.getFieldOrNull(f.name());

      // don't return copyField targets
      if (sf != null && schema.isCopyFieldTarget(sf)) continue;

      if (sf != null && sf.multiValued()) {
        List<Object> vals = new ArrayList<>();
        vals.add( f );
        out.setField( f.name(), vals );
      }
      else{
        out.setField( f.name(), f );
      }
    }
    else {
      out.addField( f.name(), f );
    }
  }
  return out;
}
 
Example #20
Source File: TopGroupsFieldCommand.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
private TopGroupsFieldCommand(Query query,
                              SchemaField field,
                              Sort groupSort,
                              Sort withinGroupSort,
                              Collection<SearchGroup<BytesRef>> firstPhaseGroups,
                              int maxDocPerGroup,
                              boolean needScores,
                              boolean needMaxScore) {
  this.query = query;
  this.field = field;
  this.groupSort = groupSort;
  this.withinGroupSort = withinGroupSort;
  this.firstPhaseGroups = firstPhaseGroups;
  this.maxDocPerGroup = maxDocPerGroup;
  this.needScores = needScores;
  this.needMaxScore = needMaxScore;
}
 
Example #21
Source File: UniqueBlockFieldAgg.java    From lucene-solr with Apache License 2.0 6 votes vote down vote up
@Override
public SlotAcc createSlotAcc(FacetContext fcontext, long numDocs, int numSlots) throws IOException {
  final String fieldName = getArg();
  SchemaField sf = fcontext.qcontext.searcher().getSchema().getField(fieldName);
  if (sf.multiValued() || sf.getType().multiValuedFieldCache()) {
    throw new IllegalArgumentException(name+"("+fieldName+
        ") doesn't allow multivalue fields, got " + sf);
  } else {
    if (sf.getType().getNumberType() != null) {
      throw new IllegalArgumentException(name+"("+fieldName+
          ") not yet support numbers " + sf);
    } else {
      return new UniqueBlockSlotAcc(fcontext, sf, numSlots);
    }
  }
}
 
Example #22
Source File: TestIndexSearcher.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
@SuppressWarnings({"unchecked"})
private String getStringVal(SolrQueryRequest sqr, String field, int doc) throws IOException {
  SchemaField sf = sqr.getSchema().getField(field);
  ValueSource vs = sf.getType().getValueSource(sf, null);
  @SuppressWarnings({"rawtypes"})
  Map context = ValueSource.newContext(sqr.getSearcher());
  vs.createWeight(context, sqr.getSearcher());
  IndexReaderContext topReaderContext = sqr.getSearcher().getTopReaderContext();
  List<LeafReaderContext> leaves = topReaderContext.leaves();
  int idx = ReaderUtil.subIndex(doc, leaves);
  LeafReaderContext leaf = leaves.get(idx);
  FunctionValues vals = vs.getValues(context, leaf);
  return vals.strVal(doc-leaf.docBase);
}
 
Example #23
Source File: AlfrescoFieldMapperTransformer.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@SuppressWarnings("unchecked")
@Override
public void transform(SolrDocument doc, int docid, float score)
{
    Collection<String> fieldNames = new ArrayList<>(doc.getFieldNames());
    solrReturnFields = new SolrReturnFields(context.getRequest().getParams().get("originalFl"), context.getRequest());

    for (String fieldName : fieldNames)
    {
       SchemaField schemaField = context.getSearcher().getSchema().getFieldOrNull(fieldName);
       if(schemaField != null)
       {
           String alfrescoFieldName = AlfrescoSolrDataModel.getInstance().getAlfrescoPropertyFromSchemaField(fieldName);
           if (isRequestedField(alfrescoFieldName) || alfrescoFieldName.equals("id"))
           {
               Object value = doc.getFieldValue(fieldName);
               doc.removeFields(fieldName);
               if (schemaField.multiValued())
               {
                   Object collectionValue =
                           ((Collection<Object>) value).stream()
                                .map(elem -> getFieldValue(schemaField, elem))
                                .collect(Collectors.toSet());
                   doc.setField(alfrescoFieldName, collectionValue);
               }
               else
               {
                   doc.setField(transformToUnderscoreNotation(alfrescoFieldName), getFieldValue(schemaField, value));
               }
           }
           else
           {
               doc.removeFields(alfrescoFieldName);
               doc.removeFields(fieldName);
           }
       }
    }
}
 
Example #24
Source File: StripLocaleStrField.java    From SearchServices with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public List<IndexableField> createFields(SchemaField field, Object value, float boost)
{
    Object newValue =
            ofNullable(value).map(String.class::cast)
                    .map(v -> v.replaceFirst("\\x{0000}.*\\x{0000}", ""))
                    .orElse(null);
    return super.createFields(field, newValue, boost);
}
 
Example #25
Source File: SolrIndexSplitter.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
SplittingQuery(int partition, SchemaField field, DocRouter.Range[] rangesArr, HashBasedRouter hashRouter, String splitKey,
               Map<IndexReader.CacheKey, FixedBitSet[]> docsToDelete, AtomicInteger currentPartition) {
  this.partition = partition;
  this.field = field;
  this.rangesArr = rangesArr;
  this.hashRouter = hashRouter;
  this.splitKey = splitKey;
  this.docsToDelete = docsToDelete;
  this.currentPartition = currentPartition;
}
 
Example #26
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * Returns a count of the documents in the set which do not have any 
 * terms for for the specified field.
 *
 * @see FacetParams#FACET_MISSING
 */
public static int getFieldMissingCount(SolrIndexSearcher searcher, DocSet docs, String fieldName)
  throws IOException {
  SchemaField sf = searcher.getSchema().getField(fieldName);
  DocSet hasVal = searcher.getDocSet
      (sf.getType().getRangeQuery(null, sf, null, null, false, false));
  return docs.andNotSize(hasVal);
}
 
Example #27
Source File: SimpleFacets.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private int numDocs(String term, final SchemaField sf, final FieldType ft, final DocSet baseDocset) {
  try {
    return searcher.numDocs(ft.getFieldQuery(null, sf, term), baseDocset);
  } catch (IOException e1) {
    throw new RuntimeException(e1);
  }
}
 
Example #28
Source File: SearchGroupsResultTransformer.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
private Object[] serializeOneSearchGroup(SortField[] groupSortField, SearchGroup<BytesRef> searchGroup) {
  Object[] convertedSortValues = new Object[searchGroup.sortValues.length];
  for (int i = 0; i < searchGroup.sortValues.length; i++) {
    Object sortValue = searchGroup.sortValues[i];
    SchemaField field = groupSortField[i].getField() != null ?
        searcher.getSchema().getFieldOrNull(groupSortField[i].getField()) : null;
    convertedSortValues[i] = ShardResultTransformerUtils.marshalSortValue(sortValue, field);
  }
  return convertedSortValues;
}
 
Example #29
Source File: LukeRequestHandler.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
/**
 * @return a string representing a SchemaField's flags.  
 */
private static String getFieldFlags( SchemaField f )
{
  FieldType t = (f==null) ? null : f.getType();

  // see: http://www.nabble.com/schema-field-properties-tf3437753.html#a9585549
  boolean lazy = false; // "lazy" is purely a property of reading fields
  boolean binary = false; // Currently not possible

  StringBuilder flags = new StringBuilder();
  flags.append( (f != null && f.indexed())             ? FieldFlag.INDEXED.getAbbreviation() : '-' );
  flags.append( (t != null && t.isTokenized())         ? FieldFlag.TOKENIZED.getAbbreviation() : '-' );
  flags.append( (f != null && f.stored())              ? FieldFlag.STORED.getAbbreviation() : '-' );
  flags.append( (f != null && f.hasDocValues())        ? FieldFlag.DOC_VALUES.getAbbreviation() : "-" );
  flags.append( (f != null && f.isUninvertible())      ? FieldFlag.UNINVERTIBLE.getAbbreviation() : "-" );
  flags.append( (f != null && f.multiValued())         ? FieldFlag.MULTI_VALUED.getAbbreviation() : '-' );
  flags.append( (f != null && f.storeTermVector() )    ? FieldFlag.TERM_VECTOR_STORED.getAbbreviation() : '-' );
  flags.append( (f != null && f.storeTermOffsets() )   ? FieldFlag.TERM_VECTOR_OFFSET.getAbbreviation() : '-' );
  flags.append( (f != null && f.storeTermPositions() ) ? FieldFlag.TERM_VECTOR_POSITION.getAbbreviation() : '-' );
  flags.append( (f != null && f.storeTermPayloads() )  ? FieldFlag.TERM_VECTOR_PAYLOADS.getAbbreviation() : '-' );
  flags.append( (f != null && f.omitNorms())           ? FieldFlag.OMIT_NORMS.getAbbreviation() : '-' );
  flags.append( (f != null &&
      f.omitTermFreqAndPositions() )        ? FieldFlag.OMIT_TF.getAbbreviation() : '-' );
  flags.append( (f != null && f.omitPositions() )      ? FieldFlag.OMIT_POSITIONS.getAbbreviation() : '-' );
  flags.append( (f != null && f.storeOffsetsWithPositions() )      ? FieldFlag.STORE_OFFSETS_WITH_POSITIONS.getAbbreviation() : '-' );
  flags.append( (lazy)                                 ? FieldFlag.LAZY.getAbbreviation() : '-' );
  flags.append( (binary)                               ? FieldFlag.BINARY.getAbbreviation() : '-' );
  flags.append( (f != null && f.sortMissingFirst() )   ? FieldFlag.SORT_MISSING_FIRST.getAbbreviation() : '-' );
  flags.append( (f != null && f.sortMissingLast() )    ? FieldFlag.SORT_MISSING_LAST.getAbbreviation() : '-' );
  return flags.toString();
}
 
Example #30
Source File: DeleteUpdateCommand.java    From lucene-solr with Apache License 2.0 5 votes vote down vote up
public String getId() {
  if (id == null && indexedId != null) {
    IndexSchema schema = req.getSchema();
    SchemaField sf = schema.getUniqueKeyField();
    if (sf != null) {
      CharsRefBuilder ref = new CharsRefBuilder();
      sf.getType().indexedToReadable(indexedId, ref);
      id = ref.toString();
    }
  }
  return id;
}