Package org.apache.solr.schema

Examples of org.apache.solr.schema.IndexSchema


  private static SimpleOrderedMap<Object> getIndexedFieldsInfo(
    final SolrIndexSearcher searcher, final Set<String> fields, final int numTerms )
    throws Exception {

    IndexReader reader = searcher.getReader();
    IndexSchema schema = searcher.getSchema();
   
    // Walk the term enum and keep a priority queue for each map in our set
    Map<String,TopTermQueue> ttinfo = null;
    if( numTerms > 0 ) {
      ttinfo = getTopTerms(reader, fields, numTerms, null );
    }
    SimpleOrderedMap<Object> finfo = new SimpleOrderedMap<Object>();
    Collection<String> fieldNames = reader.getFieldNames(IndexReader.FieldOption.ALL);
    for (String fieldName : fieldNames) {
      if( fields != null && !fields.contains( fieldName ) ) {
        continue; // if a field is specified, only them
      }
     
      SimpleOrderedMap<Object> f = new SimpleOrderedMap<Object>();
     
      SchemaField sfield = schema.getFieldOrNull( fieldName );
      FieldType ftype = (sfield==null)?null:sfield.getType();

      f.add( "type", (ftype==null)?null:ftype.getTypeName() );
      f.add( "schema", getFieldFlags( sfield ) );
      if (sfield != null && schema.isDynamicField(sfield.getName()) && schema.getDynamicPattern(sfield.getName()) != null) {
        f.add("dynamicBase", schema.getDynamicPattern(sfield.getName()));
      }

      // If numTerms==0, the call is just asking for a quick field list
      if( ttinfo != null && sfield != null && sfield.indexed() ) {
        Query q = new ConstantScoreRangeQuery(fieldName,null,null,false,false);
View Full Code Here


      return results;
    }
   
    public NamedList<DocList> getMoreLikeThese( DocList docs, int rows, int flags ) throws IOException
    {
      IndexSchema schema = searcher.getSchema();
      NamedList<DocList> mlt = new SimpleOrderedMap<DocList>();
      DocIterator iterator = docs.iterator();
      while( iterator.hasNext() ) {
        int id = iterator.nextDoc();
       
        DocListAndSet sim = getMoreLikeThis( id, 0, rows, null, null, flags );
        String name = schema.printableUniqueKey( reader.document( id ) );

        mlt.add(name, sim.docList);
      }
      return mlt;
    }
View Full Code Here

      }

      log.info("Opening new SolrCore at " + Config.getInstanceDir() + ", dataDir="+dataDir);

      if (schema==null) {
        schema = new IndexSchema("schema.xml");
      }

      this.schema = schema;
      this.dataDir = dataDir;
      this.index_path = dataDir + "/" + "index";
View Full Code Here

                throw new TapException("Only one Solr core is supported");
            } else {
                core = cores.iterator().next();
            }

            IndexSchema schema = core.getLatestSchema();
            Map<String, SchemaField> solrFields = schema.getFields();
            Set<String> schemeFieldnames = new HashSet<String>();

            for (int i = 0; i < schemeFields.size(); i++) {
                String fieldName = schemeFields.get(i).toString();
                if (!solrFields.containsKey(fieldName)) {
View Full Code Here

  public TestHarness(String dataDirectory,
                     String confFile,
                     String schemaFile) {
    try {
      SolrConfig.initConfig(confFile);
      core = new SolrCore(dataDirectory, new IndexSchema(schemaFile));
      builder = DocumentBuilderFactory.newInstance().newDocumentBuilder();
     
      updater = new XmlUpdateRequestHandler();
      updater.init( null );
    } catch (Exception e) {
View Full Code Here

      SolrParams params = req.getParams();
     
      int flags = 0;
     
      SolrIndexSearcher s = req.getSearcher();
      IndexSchema schema = req.getSchema();
           
      Map<String,Float> queryFields = U.parseFieldBoosts(params.getParams(DMP.QF));
      Map<String,Float> phraseFields = U.parseFieldBoosts(params.getParams(DMP.PF));

      float tiebreaker = params.getFloat(DMP.TIE, 0.0f);
           
      int pslop = params.getInt(DMP.PS, 0);
      int qslop = params.getInt(DMP.QS, 0);

      /* a generic parser for parsing regular lucene queries */
      QueryParser p = schema.getSolrQueryParser(null);

      /* a parser for dealing with user input, which will convert
       * things to DisjunctionMaxQueries
       */
      U.DisjunctionMaxQueryParser up =
View Full Code Here

    assertFalse(oldSchemaXml.exists());

    SolrLocator locator = new SolrLocator(new MorphlineContext.Builder().build());
    locator.setCollectionName("managedSchemaCollection");
    locator.setSolrHomeDir(solrHomeDir.getAbsolutePath());
    IndexSchema schema = locator.getIndexSchema();
    assertNotNull(schema);
    schema.getField("test-managed-morphline-field");
  }
View Full Code Here

      this.outputFieldName = getConfigs().getString(config, "outputField");     
      String solrFieldType = getConfigs().getString(config, "solrFieldType");     
      Config solrLocatorConfig = getConfigs().getConfig(config, "solrLocator");
      SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
      LOG.debug("solrLocator: {}", locator);
      IndexSchema schema = locator.getIndexSchema();
      FieldType fieldType = schema.getFieldTypeByName(solrFieldType);
      if (fieldType == null) {
        throw new MorphlineCompilationException("Missing Solr field type in schema.xml for name: " + solrFieldType, config);
      }
      this.analyzer = fieldType.getAnalyzer();
      Preconditions.checkNotNull(analyzer);
View Full Code Here

      this.preserveExisting = getConfigs().getBoolean(config, "preserveExisting", true);     
     
      Config solrLocatorConfig = getConfigs().getConfig(config, "solrLocator");
      SolrLocator locator = new SolrLocator(solrLocatorConfig, context);
      LOG.debug("solrLocator: {}", locator);
      IndexSchema schema = locator.getIndexSchema();
      SchemaField uniqueKey = schema.getUniqueKeyField();
      uniqueKeyName = uniqueKey == null ? null : uniqueKey.getName();
     
      String tmpIdPrefix = getConfigs().getString(config, "idPrefix", null)// for load testing only
      Random tmpRandomIdPrefx = null;
      if ("random".equals(tmpIdPrefix)) { // for load testing only
View Full Code Here

    return new SolrServerDocumentLoader(solrServer, batchSize);
  }

  public IndexSchema getIndexSchema() {
    if (context instanceof SolrMorphlineContext) {   
      IndexSchema schema = ((SolrMorphlineContext)context).getIndexSchema();
      if (schema != null) {
        validateSchema(schema);
        return schema;
      }
    }

    File downloadedSolrHomeDir = null;
    try {
      // If solrHomeDir isn't defined and zkHost and collectionName are defined
      // then download schema.xml and solrconfig.xml, etc from zk and use that as solrHomeDir
      String mySolrHomeDir = solrHomeDir;
      if (solrHomeDir == null || solrHomeDir.length() == 0) {
        if (zkHost == null || zkHost.length() == 0) {
          // TODO: implement download from solrUrl if specified
          throw new MorphlineCompilationException(
              "Downloading a Solr schema requires either parameter 'solrHomeDir' or parameters 'zkHost' and 'collection'",
              config);
        }
        if (collectionName == null || collectionName.length() == 0) {
          throw new MorphlineCompilationException(
              "Parameter 'zkHost' requires that you also pass parameter 'collection'", config);
        }
        ZooKeeperDownloader zki = new ZooKeeperDownloader();
        SolrZkClient zkClient = zki.getZkClient(zkHost);
        try {
          String configName = zki.readConfigName(zkClient, collectionName);
          downloadedSolrHomeDir = Files.createTempDir();
          downloadedSolrHomeDir = zki.downloadConfigDir(zkClient, configName, downloadedSolrHomeDir);
          mySolrHomeDir = downloadedSolrHomeDir.getAbsolutePath();
        } catch (KeeperException e) {
          throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } catch (InterruptedException e) {
          throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } catch (IOException e) {
          throw new MorphlineCompilationException("Cannot download schema.xml from ZooKeeper", config, e);
        } finally {
          zkClient.close();
        }
      }
     
      LOG.debug("SolrLocator loading IndexSchema from dir {}", mySolrHomeDir);
      try {
        SolrResourceLoader loader = new SolrResourceLoader(mySolrHomeDir);
        SolrConfig solrConfig = new SolrConfig(loader, "solrconfig.xml", null);
       
        IndexSchema schema = IndexSchemaFactory.buildIndexSchema("schema.xml", solrConfig);
        validateSchema(schema);
        return schema;
      } catch (ParserConfigurationException e) {
        throw new MorphlineRuntimeException(e);
      } catch (IOException e) {
View Full Code Here

TOP

Related Classes of org.apache.solr.schema.IndexSchema

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.