Read index settings
@param root dir within the classpath
@param index index name
@return Settings
@throws IOException if connection with elasticsearch is failing
3809
public static String readSettings(String root, String index) throws IOException {
		if (root == null) {
			return readSettings(index);
		}
		return readSettings(root, index, Defaults.IndexSettingsFileName);
	}
1027715
private LzoIndex readIndex(Path file, FileSystem fs) throws IOException {
    FSDataInputStream indexIn = null;
    try {
      Path indexFile = new Path(file.toString() + LZO_INDEX_SUFFIX);
      if (!fs.exists(indexFile)) {
        // return empty index, fall back to the unsplittable mode
        return new LzoIndex();
      }

      long indexLen = fs.getFileStatus(indexFile).getLen();
      int blocks = (int) (indexLen / 8);
      LzoIndex index = new LzoIndex(blocks);
      indexIn = fs.open(indexFile);
      for (int i = 0; i < blocks; i++) {
        index.set(i, indexIn.readLong());
      }
      return index;
    } finally {
      if (indexIn != null) {
        indexIn.close();
      }
    }
  }
82486
private void mapAndRememberIndexFile(File index) {
        MappedFileReader idxFileReader = null;
        try {
            idxFileReader = new MappedFileReader(index);
            mappedIndexFileReader.add(idxFileReader);
            indexFiles.add(idxFileReader.map());
        } catch(IOException e) {
            logger.error("Error mmapping " + index, e);
        }
    }
1230965
public boolean isExistingIndex(String index) throws IOException {
        logger.debug("is existing index [{}]", index);
        GetIndexRequest gir = new GetIndexRequest();
        gir.indices(index);
        return client.indices().exists(gir, RequestOptions.DEFAULT);
    }
421562
public void indexSourceTree(final Folder rootFolder) {

		logger.info("Starting indexing of source tree " + rootFolder.getPath());

		final SecurityContext securityContext = rootFolder.getSecurityContext();
		app = StructrApp.getInstance(securityContext);

		structrTypeSolver.parseRoot(rootFolder);

		final CombinedTypeSolver typeSolver = new CombinedTypeSolver();
		typeSolver.add(new ReflectionTypeSolver());
		typeSolver.add(structrTypeSolver);

		facade = JavaParserFacade.get(typeSolver);

		logger.info("Done with indexing of source tree " + rootFolder.getPath());
	}
208266
@Deprecated
	private static void createIndexWithSettingsInElasticsearch(Client client, String index, String settings) throws Exception {
		logger.trace("createIndex([{}])", index);

		assert client != null;
		assert index != null;

		CreateIndexRequestBuilder cirb = client.admin().indices().prepareCreate(index);

		// If there are settings for this index, we use it. If not, using Elasticsearch defaults.
		if (settings != null) {
			logger.trace("Found settings for index [{}]: [{}]", index, settings);
			cirb.setSource(settings, XContentType.JSON);
		}

		CreateIndexResponse createIndexResponse = cirb.execute().actionGet();
		if (!createIndexResponse.isAcknowledged()) {
			logger.warn("Could not create index [{}]", index);
			throw new Exception("Could not create index ["+index+"].");
		}

		logger.trace("/createIndex([{}])", index);
	}
909860
public static List<String> findTypes(String root, String index) throws IOException, URISyntaxException {
        if (root == null) {
            return findTypes(index);
        }

        logger.debug("Looking for types in classpath under [{}/{}].", root, index);

        final List<String> typeNames = new ArrayList<>();
        String[] resources = ResourceList.getResources(root + "/" + index + "/"); // "es/index/"
        for (String resource : resources) {
            if (!resource.isEmpty() && !root.equals(resource)) {
                String withoutIndex = resource.substring(resource.indexOf("/") + 1);
                if (withoutIndex.equals(Defaults.IndexSettingsFileName) ||
                        withoutIndex.equals(Defaults.UpdateIndexSettingsFileName)) {
                    logger.trace(" - ignoring: [{}]", withoutIndex);
                } else {
                    String type = withoutIndex.substring(0, withoutIndex.indexOf(Defaults.JsonFileExtension));
                    logger.trace(" - found [{}].", type);
                    typeNames.add(type);
                }
            }
        }

        return typeNames;
    }
492770
public ByteBuffer get(final int index) {
		if (!validState) {
			throw new InvalidStateException();
		}
		if (log.isDebugEnabled()) {
			log.debug("get(" + index + ")");
		}
		try {
			if (useMmap) {
				final MappedByteBuffer mbb = getMmapForIndex(index);
				if (mbb != null) {
					return mbb;
				}
				// Fallback to RAF
			}
			final ByteBuffer buf = bufstack.pop();
			fileChannel.position(index * blockSize).read(buf);
			buf.rewind();
			return buf;
		} catch (Exception e) {
			log.error("Exception in get(" + index + ")", e);
		}
		return null;
	}
717854
def index_path(self, root):
        
        basename = os.path.basename(root)
        if os.path.splitext(basename)[0] != '__init__' and basename.startswith('_'):
            return
        location = self._determine_location_for(root)
        if os.path.isfile(root):
            self._index_module(root, location)
        elif os.path.isdir(root) and os.path.exists(os.path.join(root, '__init__.py')):
            self._index_package(root, location)
308133
protected void buildIndexMap(RootDoc root)  {
        PackageDoc[] packages = root.specifiedPackages();
        ClassDoc[] classes = root.classes();
        if (!classesOnly) {
            if (packages.length == 0) {
                Set<PackageDoc> set = new HashSet<PackageDoc>();
                PackageDoc pd;
                for (int i = 0; i < classes.length; i++) {
                    pd = classes[i].containingPackage();
                    if (pd != null && pd.name().length() > 0) {
                        set.add(pd);
                    }
                }
                adjustIndexMap(set.toArray(packages));
            } else {
                adjustIndexMap(packages);
            }
        }
        adjustIndexMap(classes);
        if (!classesOnly) {
            for (int i = 0; i < classes.length; i++) {
                if (shouldAddToIndexMap(classes[i])) {
                    putMembersInIndexMap(classes[i]);
                }
            }
        }
        sortIndexMap();
    }
1291479
private void esIndex(String index, String id, String json, String pipeline) {
        logger.debug("Indexing {}/{}?pipeline={}", index, id, pipeline);
        logger.trace("JSon indexed : {}", json);

        if (!closed) {
            esClient.index(index, id, json, pipeline);
        } else {
            logger.warn("trying to add new file while closing crawler. Document [{}]/[{}] has been ignored", index, id);
        }
    }
33221
def index(self, index):
        
        if self._index != index:
            self._dirty = True
        self._index = index
64639
void copyIndex(final AbstractIndex index) throws IOException
   {
      // commit changes to directory on other index.
      index.commit(true);
      // simply copy over the files
      byte[] buffer = new byte[1024];
      Directory dir = index.getDirectory();
      Directory dest = getDirectory();
      String[] files = dir.listAll();
      for (int i = 0; i < files.length; i++)
      {
         IndexInput in = dir.openInput(files[i]);
         try
         {
            IndexOutput out = dest.createOutput(files[i]);
            try
            {
               long remaining = in.length();
               while (remaining > 0)
               {
                  int num = (int)Math.min(remaining, buffer.length);
                  in.readBytes(buffer, 0, num);
                  out.writeBytes(buffer, num);
                  remaining -= num;
               }
            }
            finally
            {
               out.close();
            }
         }
         finally
         {
            in.close();
         }
      }
   }
446245
private File resolveIndexDirectoryPath() throws IOException {
        if (StringUtils.isEmpty(indexDirectoryPath)) {
            indexDirectoryPath = System.getProperty("java.io.tmpdir") + appContext.getApplicationName();
        }
        
        File dir = new File(indexDirectoryPath, getClass().getPackage().getName());
        
        if (!dir.exists() && !dir.mkdirs()) {
            throw new IOException("Failed to create help search index directory.");
        }
        
        log.info("Help search index located at " + dir);
        return dir;
    }
175153
public Index createResourceIndex() throws Exception {
        if (!ResourceIndex.INSTANCE.isLoaded()) {
            // Load resource index defined by the BELFramework instance
            final SystemConfiguration sysConfig = getSystemConfiguration();
            final String resourceIndexURL = sysConfig.getResourceIndexURL();
            File indexFile = new File(resourceIndexURL);
            if (!indexFile.exists() || !indexFile.canRead()) {
                // try the index as an online resource.
                ResolvedResource resolvedResource = cacheService
                        .resolveResource(ResourceType.RESOURCE_INDEX,
                                resourceIndexURL);
                indexFile = resolvedResource.getCacheResourceCopy();
            }

            ResourceIndex.INSTANCE.loadIndex(indexFile);
        }
        return ResourceIndex.INSTANCE.getIndex();
    }
363194
public JSONObject getSettings(RequestOptions requestOptions) throws AlgoliaException {
    return client.getRequest("/1/indexes/" + encodedIndexName + "/settings?getVersion=2", false, requestOptions);
  }
1285176
private static void createIndexWithSettingsInElasticsearch(RestClient client, String index, String settings) throws Exception {
		logger.trace("createIndex([{}])", index);

		assert client != null;
		assert index != null;

        Request request = new Request("PUT", "/" + index);

		// If there are settings for this index, we use it. If not, using Elasticsearch defaults.
		if (settings != null) {
			logger.trace("Found settings for index [{}]: [{}]", index, settings);
			request.setJsonEntity(settings);
		}

        Response response = client.performRequest(request);
		if (response.getStatusLine().getStatusCode() != 200) {
			logger.warn("Could not create index [{}]", index);
			throw new Exception("Could not create index ["+index+"].");
		}

		logger.trace("/createIndex([{}])", index);
	}