List of usage examples for org.apache.solr.schema IndexSchema getFieldTypeNoEx
public FieldType getFieldTypeNoEx(String fieldName)
From source file:CartesianTierQParserPlugin.java
License:Apache License
public QParser createParser(String qstr, SolrParams localParams, SolrParams params, SolrQueryRequest req) { return new QParser(qstr, localParams, params, req) { public Query parse() throws ParseException { final Double x = localParams.getDouble("x"); final Double y = localParams.getDouble("y"); final String fieldPrefix = localParams.get("prefix", tierPrefix); final Double distance = localParams.getDouble("dist"); //GSI: kind of funky passing in an empty string, but AFAICT, it is safe b/c we don't want to assume tier prefix stuff CartesianPolyFilterBuilder cpfb = new CartesianPolyFilterBuilder(fieldPrefix); //Get the box based on this point and our distance final Shape shape = cpfb.getBoxShape(x, y, distance); final List<Double> boxIds = shape.getArea(); //Sort them, so they are in order, which will be faster for termdocs in the tier filter Collections.sort(boxIds); //Get the field type so we can properly encode the data IndexSchema schema = req.getSchema(); FieldType ft = schema.getFieldTypeNoEx(shape.getTierId()); //Create the Filter and wrap it in a constant score query Filter filter = new TierFilter(shape.getTierId(), ft, boxIds); return new SolrConstantScoreQuery(filter); }/*from w w w . java 2 s . c om*/ }; }
From source file:com.sindicetech.siren.solr.handler.mapper.FieldMappersHandler.java
License:Open Source License
private void addSchemaField(FieldMapper mapper, FieldEntry entry) { if (!core.getLatestSchema().isMutable()) { final String message = "This IndexSchema is not mutable."; throw new SolrException(BAD_REQUEST, message); }// w w w.ja va 2 s . co m for (;;) { final IndexSchema oldSchema = core.getLatestSchema(); if (oldSchema.getFieldTypeNoEx(mapper.getTargetFieldname(entry)) != null) { return; // the field already exists in the schema } try { SchemaField field = mapper.getSchemaField(core.getLatestSchema(), entry); IndexSchema newSchema = oldSchema.addField(field); if (newSchema != null) { core.setLatestSchema(newSchema); logger.debug("Successfully added field '{}' to the schema.", field.getName()); return; // success - exit from the retry loop } else { throw new SolrException(SolrException.ErrorCode.SERVER_ERROR, "Failed to add fields."); } } catch (ManagedIndexSchema.FieldExistsException e) { logger.debug("The field to be added already exists in the schema - retrying."); // No action: at least one field to be added already exists in the schema, so retry // We should never get here, since oldSchema.getFieldTypeNoEx(field) will exclude already existing fields } catch (ManagedIndexSchema.SchemaChangedInZkException e) { logger.debug("Schema changed while processing request - retrying."); } } }
From source file:in.geocoder.component.GeocodingComponent.java
License:Apache License
private NamedList<Integer> getTerms(SolrIndexSearcher searcher, IndexSchema schema, String field) throws IOException { NamedList<Object> termsResult = new SimpleOrderedMap<Object>(); boolean sort = true; boolean raw = false; final AtomicReader indexReader = searcher.getAtomicReader(); Fields lfields = indexReader.fields(); NamedList<Integer> fieldTerms = new NamedList<Integer>(); termsResult.add(field, fieldTerms);/*from w w w .j a v a2 s . c o m*/ Terms terms = lfields == null ? null : lfields.terms(field); if (terms == null) { // no terms for this field return new NamedList<Integer>(); } FieldType ft = raw ? null : schema.getFieldTypeNoEx(field); if (ft == null) ft = new StrField(); TermsEnum termsEnum = terms.iterator(null); BytesRef term = null; term = termsEnum.next(); BoundedTreeSet<CountPair<BytesRef, Integer>> queue = (sort ? new BoundedTreeSet<CountPair<BytesRef, Integer>>(Integer.MAX_VALUE) : null); CharsRef external = new CharsRef(); while (term != null) { boolean externalized = false; // did we fill in "external" yet for this term? // This is a good term in the range. Check if mincount/maxcount conditions are satisfied. int docFreq = termsEnum.docFreq(); // add the term to the list if (sort) { queue.add(new CountPair<BytesRef, Integer>(BytesRef.deepCopyOf(term), docFreq)); } else { // TODO: handle raw somehow if (!externalized) { ft.indexedToReadable(term, external); } fieldTerms.add(external.toString(), docFreq); } term = termsEnum.next(); } if (sort) { for (CountPair<BytesRef, Integer> item : queue) { ft.indexedToReadable(item.key, external); fieldTerms.add(external.toString(), item.val); } } return fieldTerms; }