Core function to search the indexes and return data
423750
def search(self, searchString, category="", math=False, game=False, searchFiles=False, extension=""):
		""""""
		data = []
		nameData = {}
		fileData = {}
		
		#Search the name index
		if searchFiles:
			fileData = self.searchNamesIndex(self.fileIndex, fileData, searchString, category, math, game, extension, searchFiles)
		else:
			nameData = self.searchNamesIndex(self.nameIndex, nameData, searchString)
			
		#Now search the file index
		if searchFiles:
			nameData, fileData = self.searchFilesIndex(fileData, nameData, self.nameIndex, searchString)
		else:
			fileData, nameData = self.searchFilesIndex(nameData, fileData, self.fileIndex, searchString, category, math, game, extension)
			
		# Bail out if we failed to do either of those things.
		if fileData is None or nameData is None:
			self.repo.printd("Error: failed to load one or more of the index files for this repo. Exiting.")
			self.repo.printd("Please run 'calcpkg update' and retry this command.")
			sys.exit(1)
			
		# Prepare output to parse
		space = 0
		longestFile = len("File Name:")
		for key, value in nameData.iteritems():
			fileValue = fileData[key]
			data.append([fileValue, value])
			if not fileValue is None:
				folder = fileValue.rpartition("/")[0]
				if space < len(folder):
					space = len(folder)
			if not value is None:
				if longestFile < len(value):
					longestFile = len(value)

		#Print output
		space += 5
		if len(data) != 0:
			self.repo.printd("Results for repo: " + self.repo.name)
			self.repo.printd(structureOutput("File Category:", "File Name:", False, False, space))
			self.repo.printd("-" * (space + longestFile))
		else:
			self.repo.printd("No packages found")
		returnData = []
		for datum in data:
			try:
				self.repo.printd(structureOutput(datum[0], datum[1], searchFiles, True, space))
				returnData.append([datum[0], datum[1]])
			except:
				pass
		self.repo.printd(" ")
		
		#Return data
		return returnData
1021002
def list(self, request):
        """"""
        query = get_query_params(request).get("search", "")
        results = []
        base = self.model.get_base_class()
        doctypes = indexable_registry.families[base]
        for doctype, klass in doctypes.items():
            name = klass._meta.verbose_name.title()
            if query.lower() in name.lower():
                results.append(dict(
                    name=name,
                    doctype=doctype
                ))
                results.sort(key=lambda x: x["name"])
        return Response(dict(results=results))
286900
def getIndexes(self) :
        """"""
        url = "%s/index" % self.database.URL
        r = self.connection.session.get(url, params = {"collection": self.name})
        data = r.json()
        for ind in data["indexes"] :
            self.indexes[ind["type"]][ind["id"]] = Index(collection = self, infos = ind)

        return self.indexes
388450
def _get_indexes(self, schema, **kwargs):
        """"""
        # http://www.sqlite.org/pragma.html#schema
        # http://www.mail-archive.com/sqlite-users@sqlite.org/msg22055.html
        # http://stackoverflow.com/questions/604939/
        ret = {}
        rs = self._query('PRAGMA index_list({})'.format(self._normalize_table_name(schema)), **kwargs)
        if rs:
            for r in rs:
                iname = r['name']
                ret.setdefault(iname, [])
                indexes = self._query('PRAGMA index_info({})'.format(r['name']), **kwargs)
                for idict in indexes:
                    ret[iname].append(idict['name'])

        return ret
313737
function findMatchingIndexes(selector, userFields, sortOrder, indexes) {

  return indexes.reduce(function (res, index) {
    var indexMatches = checkIndexMatches(index, sortOrder, userFields, selector);
    if (indexMatches) {
      res.push(index);
    }
    return res;
  }, []);
}
1008514
def find_by_index(self, cls, index_name, value):
        """"""
        query_args = {
            index_name + '__eq': DynamoMappings.map_index_val(value),
            'index': gsi_name(index_name)
        }

        final_results = []
        for db_result in self.get_class_table(cls).query_2(**query_args):
            obj = cls.from_data(db_result['value'])
            final_results.append(obj)

        return final_results
1347612
def search(query, index=INDEX_NAME, doc_type=DOC_TYPE):
    
    results = raw_query(query, index=index, doc_type=doc_type)
    return [r['_source'] for r in results]
296380
public <T> ESDatas<T> searchAllParallel(String index,  int fetchSize ,Class<T> type,int thread) throws ElasticSearchException{
		return searchAllParallel(index,  fetchSize,(ScrollHandler<T>)null,type,thread);
	}
290936
def index(self, refresh=False):
        """"""
        es = connections.get_connection("default")
        index = self.__class__.search_objects.mapping.index
        doc_type = self.__class__.search_objects.mapping.doc_type
        es.index(index, doc_type,
                 id=self.pk,
                 body=self.to_dict(),
                 refresh=refresh)
788106
def search(self, start_ts, end_ts):
        """"""
        query = '_ts: [%s TO %s]' % (start_ts, end_ts)
        return self._stream_search(query)
1249982
def search_datasets(self, search_phrase, limit=None):
        
        return self.backend.dataset_index.search(search_phrase, limit=limit)
329277
def find(self, query=None, limit=None):
        
        results = []
        query = query or {}

        # TODO: When indexes are implemented, we'll need to intelligently hit one of the
        # index stores so we don't do a full table scan
        cursor = self.db.execute("select id, data from %s" % self.name)
        apply = partial(self._apply_query, query)

        for match in filter(apply, starmap(self._load, cursor.fetchall())):
            results.append(match)

            # Just return if we already reached the limit
            if limit and len(results) == limit:
                return results

        return results
1057304
function (db, indexName, facetDoc, query, cb) {
			var url = host + "databases/" + db + "/facets/" + indexName + "?facetDoc=" + facetDoc + "&query=" + encodeURIComponent(query);
			request(url, function (error, response, body) {
				if (!error && response.statusCode === 200) {
					var result = JSON.parse(body);
					_.each(result.Results, function (v, k) {
						if (_.filter(v.Values, function (x) {
							return x.Hits > 0;
						}).length < 2) {
							delete result.Results[k];
							return;
						}
						v.Values = _.chain(v.Values)
							.map(function (x) {
								var val = JSON.stringify(x.Range)
									.replace(/^\"|\"$/gi, "")
									.replace(/\:/gi, "\\:")
									.replace(/\(/gi, "\\(")
									.replace(/\)/gi, "\\)");
								if (x.Range.indexOf(" TO ") <= 0 || x.Range.indexOf("[") !== 0) {
									val = val.replace(/\ /gi, "\\ ");
								}
								val = encodeURIComponent(val);
								x.q = k + ":" + val;
								x.Range = x.Range
									.replace(/^\[Dx/, "")
									.replace(/ Dx/, " ")
									.replace(/\]$/, "")
									.replace(/ TO /, "-");
								return x;
							}).filter(function (x) {
								return x.Hits > 0;
							}).sortBy(function (x) {
								return x.Range;
							}).value();
					});
					cb(null, result.Results);
				} else
					cb(error || new Error(response.statusCode), null);
			});
		}
343758
def get_objects(self, search_field, search_val):
        """"""
        query = ("{ size: " + str(self.max_hits) + ", " +
                 "query: { filtered: { filter: { " +
                 search_field + ": { value: \"" + search_val + "\"" +
                 " } } } } } }")
        self.connect_es()
        res = self.es.search(index=self.index, body=query)
        # self.pr_dbg("%d Hits:" % res['hits']['total'])
        objects = {}
        for doc in res['hits']['hits']:
            objects[doc['_id']] = {}
            # To make uploading easier in the future:
            # Record all those bits into the backup.
            # Mimics how ES returns the result.
            # Prevents having to store this in some external, contrived, format
            objects[doc['_id']]['_index'] = self.index  # also in doc['_index']
            objects[doc['_id']]['_type'] = doc['_type']
            objects[doc['_id']]['_id'] = doc['_id']
            objects[doc['_id']]['_source'] = doc['_source']  # the actual result
        return objects
765311
def _query(options, collection_name, num_to_skip,
           num_to_return, query, field_selector, opts, check_keys):
    """"""
    encoded = _dict_to_bson(query, check_keys, opts)
    if field_selector:
        efs = _dict_to_bson(field_selector, False, opts)
    else:
        efs = b""
    max_bson_size = max(len(encoded), len(efs))
    return b"".join([
        _pack_int(options),
        _make_c_string(collection_name),
        _pack_int(num_to_skip),
        _pack_int(num_to_return),
        encoded,
        efs]), max_bson_size
783459
def raw_query(query, index=INDEX_NAME, doc_type=DOC_TYPE):
    
    result = es_conn.search(index=index, doc_type=DOC_TYPE, body=query)
    return result['hits']['hits']
290761
def _do_search(self):
        
        if self._results_cache is None:
            response = self.raw()
            results = self.to_python(response.get('hits', {}).get('hits', []))
            self._results_cache = DictSearchResults(
                self.type, response, results, None)
        return self._results_cache