Create the lunr index - the docs should be an array of objects, each object containing the path and search terms for a page
187595
function createIndex(addFn) {
  return lunr(/** @this */function() {
    this.pipeline.remove(lunr.stopWordFilter);
    this.ref('path');
    this.field('titleWords', {boost: 100});
    this.field('headingWords', {boost: 50});
    this.field('members', {boost: 40});
    this.field('keywords', {boost: 20});
    addFn(this);
  });
}
785751
function createDocs() {
  if(!this.config.path.docs) return;
  try {
    var hasDocFolder = fs.existsSync(Component.appPath(this.config.path.docs)),
      hasTemplate = fs.existsSync(Component.appPath(this.config.docs.template));
    if(!hasDocFolder || !hasTemplate) throw new Error("No docs");
  } catch(e) {
    // No documentation support.
    return;
  }
  var docTwig = fs.readFileSync(Component.appPath(this.config.docs.template), { encoding: 'utf8' }).toString();
  var html = viewEngine.render(docTwig, {
    locals: {
      routes: this.routes
    }
  });
  try {
    fs.writeFileSync(Component.appPath(this.config.path.docs, 'doc.html'), html, { flag: 'w', encoding: 'utf8' });
    log.trace('CruxServer: Documented %s routes in ' + this.config.path.docs, routeCount);
  } catch(e) {}
}
1336356
def create_index(self, key, reindex=True, sparse=False):
        
        warnings.warn('Index support is currently very alpha and is not guaranteed')
        if isinstance(key, (list, tuple)):
            index_name = ','.join(key)
            index_columns = ', '.join('%s text' % f for f in key)
        else:
            index_name = key
            index_columns = '%s text' % key

        table_name = '[%s{%s}]' % (self.name, index_name)
        reindex = reindex or not self._object_exists('table', table_name)

        # Create a table store for the index data
        self.db.execute("""
            create table if not exists {table} (
                id integer primary key,
                {columns},
                foreign key(id) references {collection}(id) on delete cascade on update cascade
            )
        """.format(
            table=table_name,
            collection=self.name,
            columns=index_columns
        ))

        # Create the index
        self.db.execute("""
            create index if not exists [idx.{collection}{{index}}] on {table}({index})
        """.format(
            collection=self.name,
            index=index_name,
            table=table_name,
        ))

        if reindex:
            self.reindex(key)
1146048
function createSubset(keywords, doc) {

    if (!keywords || Object.prototype.toString.call(keywords) !== '[object Array]') {
      return doc;
    }

    var lookup = createLookUp(keywords);

    return traverseThroughObject(lookup, doc);

  }
529284
private static IndexEnvironment setupIndexer(File outputDirectory, int memory,
      boolean storeDocs) throws Exception {
    final IndexEnvironment env = new IndexEnvironment();
    env.setMemory(memory * ONE_MEGABYTE);
    final Specification spec = env.getFileClassSpec("trectext");
    env.addFileClass(spec);
    env.setStoreDocs(storeDocs);
    // if we don't build indices on DOCNO then getting the docIds at query time is
    // extremely slow
    env.setMetadataIndexedFields(new String[]{"docno"}, new String[]{"docno"});
    env.create(outputDirectory.getAbsolutePath(), statusMonitor);
    return env;
  }
999631
def create_index(group, chunk_size, compression=None, compression_opts=None):
    """"""
    dtype = np.int64
    if chunk_size == 'auto':
        chunks = True
    else:
        chunks = (nb_per_chunk(np.dtype(dtype).itemsize, 1, chunk_size),)

    group.create_dataset(
        'index', (0,), dtype=dtype,
        chunks=chunks, maxshape=(None,),
        compression=compression, compression_opts=compression_opts)
1179879
function search (query) {
  if (!allowSearch) {
    console.error('Assets for search still loading');
    return;
  }

  var resultDocuments = [];
  var results = index.search(query + '~2'); // fuzzy
  for (var i=0; i < results.length; i++){
    var result = results[i];
    doc = documents[result.ref];
    doc.summary = doc.text.substring(0, 200);
    resultDocuments.push(doc);
  }
  return resultDocuments;
}
799241
def _index_document(self, document, force=False):
        
        query = text("""
            INSERT INTO dataset_index(vid, title, keywords, doc)
            VALUES(:vid, :title, :keywords, :doc);
        """)
        self.backend.library.database.connection.execute(query, **document)
826764
function(index) {
      var that = this;

      var props = this._propIndex(index);
      if (!props) {
        return Promise.reject(new Error('No auto-indexing key specified'));
      }

      return this._dbApi.find(props).then(function(docs) {
        return that._readDoc(docs[0]);
      });
    }
748171
function prepareEPUBDataForIndexing(metaData, data) {
    if(!metaData.spineItems.length) {
        return;
    }

    if (!data.FirstSpineItemsId) {
        data.FirstSpineItemsId = [];
    }

    data.FirstSpineItemsId.push(
        metaData.spineItems[0].id + ':' + metaData.title
    );

    metaData.spineItems.forEach( spineItem => {
        const spineItemPath = metaData.manifestPath + '/' + spineItem.href;
        const json = htmlToJSON(spineItemPath);
        setMetaData(json, metaData, spineItem);
        data.push(json);
    });
}
508383
function prepareEPUBDataForIndexing(metaData) {

    if (!metaData.spineItems.length)
        return;

    var data = [];

    const arrayOfPromises = metaData.spineItems.map(spineItem => {
        return helper.getContent(spineItem.href)
            .then(body => { return cheerio.load(body); })
    });

    return Promise.all(arrayOfPromises)
        .then((arrayOf$) => {

            arrayOf$.forEach(($, i) => {
                const doc = {};
                $("title").each((i, e) => {
                    doc.title = trim($(e).text());
                });
                $("body").each((i, e) => {
                    doc.body = trim($(e).text());
                });
                setMetaData(doc, metaData, metaData.spineItems[i]);
                data.push(doc);
            });
            return data;
        })
        .catch(err => {
            winston.log('error', 'prepareEPUBDataForIndexing: ' + err);
        });
}
240852
def create_indexed_document(index_instance, model_items, action):
    '''
    
    '''
    data = []
    if action == 'delete':
        for pk in model_items:
            data.append({'_id': pk, '_op_type': action})
    else:
        for doc in model_items:
            if index_instance.matches_indexing_condition(doc):
                data.append(index_instance.serialize_object(doc))
    return data
305708
public function index($object)
    {
        // create property accessor
        $accessor = PropertyAccess::createPropertyAccessor();

        // delete existing documents with same id
        foreach ($this->index->find('id:' . $accessor->getValue($object, 'id')) as $hit) {
            $this->index->delete($hit->id);
        }

        // create new Lucene document
        $doc = new Document();

        // add primary key to identify it in the search results
        $doc->addField(Field::keyword('id', $accessor->getValue($object, 'id')));

        // add entity class reference to identify it in the search results
        $doc->addField(Field::unIndexed('entityClass', get_class($object)));

        // analyze each property's annotations to see which ones must be add to the document
        $reflClass = new ReflectionClass($object);
        foreach ($reflClass->getProperties() as $property) {
            $reflProperty = new \ReflectionProperty($object, $property->name);
            $annotation = $this->reader->getPropertyAnnotation($reflProperty, '\Keratine\Lucene\Mapping\Annotation\DocumentField');
            if ($annotation) {
                $value = $accessor->getValue($object, $property->name);
                $value = $this->ensureString($value);
                // use the appropriate indexing strategy for the field
                switch ($annotation->type) {
                    case 'keyword':
                        $doc->addField(Field::keyword($property->name, $value, 'UTF-8'));
                        break;
                    case 'unIndexed':
                        $doc->addField(Field::unIndexed($property->name, $value, 'UTF-8'));
                        break;
                    case 'binary':
                        $doc->addField(Field::binary($property->name, $value));
                        break;
                    case 'text':
                        $doc->addField(Field::text($property->name, $value, 'UTF-8'));
                        break;
                    case 'unStored':
                    default:
                        $doc->addField(Field::unStored($property->name, $value, 'UTF-8'));
                        break;
                }
            }
        }

        // add the document to the index and commit it
        $this->index->addDocument($doc);
        $this->index->commit();
    }
1224849
function createIndex(addFn) {
  lunr.QueryLexer.termSeparator = lunr.tokenizer.separator = /\s+/;
  return lunr(/** @this */function() {
    this.ref('path');
    this.field('titleWords', {boost: 10});
    this.field('headingWords', {boost: 5});
    this.field('members', {boost: 4});
    this.field('keywords', {boost: 2});
    addFn(this);
  });
}
473492
function searchIndex(sQuery) {

		sQuery = preprocessQuery(sQuery);

		return new Promise(function(resolve, reject) {

			fetchIndex().then(function(oIndex) {

				var aSearchResults,
					oSearchResultsCollector = new SearchResultCollector();

				function searchByField(sFieldToSearch, sSubQuery, bReturnMatchedDocWord) {

					var aResults = oIndex.search(sSubQuery, createSearchConfig(sFieldToSearch));

					oSearchResultsCollector.add(aResults,
						sSubQuery,
						sFieldToSearch,
						bReturnMatchedDocWord);
				}

				// search by fields in priority order
				searchByField("title", sQuery);
				METADATA_FIELDS.forEach(function(sField) {
					lunr.tokenizer(sQuery).forEach(function(sSubQuery) {
						searchByField(sField, sSubQuery, true);
					});
				});
				searchByField("paramTypes", sQuery);
				searchByField("contents", sQuery);

				// collect all results
				aSearchResults = oSearchResultsCollector.getAll();


				resolve({
					success: !!(aSearchResults.length),
					totalHits: aSearchResults.length,
					matches: aSearchResults
				});
			});
		});
	}
525837
def _index_document(index_list):
    
    if isinstance(index_list, abc.Mapping):
        raise TypeError("passing a dict to sort/create_index/hint is not "
                        "allowed - use a list of tuples instead. did you "
                        "mean %r?" % list(iteritems(index_list)))
    elif not isinstance(index_list, (list, tuple)):
        raise TypeError("must use a list of (key, direction) pairs, "
                        "not: " + repr(index_list))
    if not len(index_list):
        raise ValueError("key_or_list must not be the empty list")

    index = SON()
    for (key, value) in index_list:
        if not isinstance(key, string_type):
            raise TypeError("first item in each key pair must be a string")
        if not isinstance(value, (string_type, int, abc.Mapping)):
            raise TypeError("second item in each key pair must be 1, -1, "
                            "'2d', 'geoHaystack', or another valid MongoDB "
                            "index specifier.")
        index[key] = value
    return index
185592
function createWordIndex(exampleData) {
  const index = {};
  const keys = ['shortdesc', 'title', 'tags'];
  exampleData.forEach((data, i) => {
    keys.forEach(key => {
      let text = data[key];
      if (Array.isArray(text)) {
        text = text.join(' ');
      }
      const words = text ? text.split(/\W+/) : [];
      words.forEach(word => {
        if (word) {
          word = word.toLowerCase();
          let counts = index[word];
          if (counts) {
            if (index in counts) {
              counts[i] += 1;
            } else {
              counts[i] = 1;
            }
          } else {
            counts = {};
            counts[i] = 1;
            index[word] = counts;
          }
        }
      });
    });
  });
  return index;
}