Search for records based on an entity
328262
public function getQueryPagination(Module $entity, $sort, $direction)
    {

        $queryBuilder = $this->createQueryBuilder('m');

        $data = [
            'slug' => $entity->getSlug(),
            'name' => $entity->getName(),
            'id' => $entity->getId(),
        ];

        if (!empty($data['name'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->like('m.name', ':name'))
                ->setParameter('name', "%{$data['name']}%")
            ;
        }

        if (!empty($data['slug'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->like('m.slug', ':slug'))
                ->setParameter('slug', "%{$data['slug']}%")
            ;
        }

        if (!empty($data['id'])) {
            $queryBuilder
                ->andWhere($queryBuilder->expr()->eq('m.id', ':id'))
                ->setParameter('id', $data['id'])
            ;
        }

        return $queryBuilder
            ->orderBy('m.'.$sort, $direction)
            ->getQuery()
        ;
    }
381521
public List<Entity> pageForEntityList(Entity where, Page page) throws SQLException {
		return page(where, page, EntityListHandler.create());
	}
1248488
def search(self, query, relation=None, index=0, limit=25, **kwargs):
        
        return self.get_object(
            "search", relation=relation, q=query, index=index, limit=limit, **kwargs
        )
517116
@Override
    public Map<String, Object> search(String query, Class<?> parentClass, EntityMetadata parentMetadata,
            Class<?> childClass, EntityMetadata childMetadata, Object entityId, int start, int count)
    {
        return search(parentClass, parentMetadata, query, start, count);
    }
376408
def get(self, entity, id=None, sub_entity=None, offset=0, limit=20,
            search_terms=None, sync=True):
        
        url = urljoin(self.host, entity.value + '/')
        url = urljoin(url, id + '/') if id else url
        url = urljoin(url, sub_entity.value + '/') if sub_entity else url
        terms = {'sync': str(sync).lower()}
        if search_terms:
            terms.update(search_terms)
        if not id:
            terms.update({'limit': limit, 'offset': offset})
        url = Utils.add_url_parameters(url, terms)
        r = requests.get(url, auth=self.auth, headers=self.headers)
        if sub_entity == Entity.Content:
            return r.content
        elif r.ok:
            j = r.json()

            if 'meta' not in j:
                # TODO: Fix error in API. No meta data returned when getting a
                # single object.
                return {'objects': [j]}

            next_path = j['meta']['next']

            while next_path:
                offset += limit
                url = urljoin(self.host, entity.value + '/')
                url = urljoin(url, id + '/') if id else url
                url = urljoin(
                    url, sub_entity.value + '/') if sub_entity else url
                terms = {'offset': offset}
                url = Utils.add_url_parameters(
                    url, {'offset': offset})
                r = requests.get(url, auth=self.auth, headers=self.headers)
                j['objects'].extend(r.json()['objects'])
                next_path = r.json()['meta']['next']

            return j['objects']
        else:
            raise CoredataError(
                'Error occured! Status code is {code} for {url}'.format(
                    code=r.status_code, url=url))
617061
def has_entities(status):
    
    try:
        if sum(len(v) for v in status.entities.values()) > 0:
            return True

    except AttributeError:
        if sum(len(v) for v in status['entities'].values()) > 0:
            return True

    return False
1045927
def find_by(self, values={}, **kwargs):
        
        try:
            return self(
                **self.select(
                    where=values,
                    limit=1,
                    **kwargs
                    ).to_dict(orient='records')[0]
                )
        except IndexError:
            return None
1021546
public List<EnhanceEntity> find(EntityMetadata m, List<String> relationNames, List<IndexClause> conditions,
            int maxResult, List<String> columns)
    {
        return (List<EnhanceEntity>) find(conditions, m, true, relationNames, maxResult, columns);
    }
1116162
@Transactional
    public E findUniqueOrNone(E entity, SearchParameters sp) {
        // this code is an optimization to prevent using a count
        sp.setFirst(0);
        sp.setMaxResults(2);
        List<E> results = find(entity, sp);

        if (results == null || results.isEmpty()) {
            return null;
        } else if (results.size() > 1) {
            throw new NonUniqueResultException("Developper: You expected 1 result but we found more ! sample: " + entity);
        } else {
            return results.iterator().next();
        }
    }
813703
@SuppressWarnings("unchecked")
	public <T> T findById(String id, Class<T> entity) {
		if (entity == null) {
			throw new ApitraryOrmException("Cannot access null entity");
		}
		if (id == null || id.isEmpty()) {
			return null;
		}

		log.debug("Searching " + entity.getName() + " " + id);

		GetRequest request = new GetRequest();
		request.setEntity(resolveApitraryEntity(entity));
		request.setId(id);
		GetResponse response = resolveApitraryClient().send(request);

		T result = (T) new GetResponseUnmarshaller(this).unMarshall(response, entity);

		if (result != null) {
			List<Field> fields = ClassUtil.getAnnotatedFields(entity, Id.class);
			if (fields.isEmpty() || fields.size() > 1) {
				throw new ApitraryOrmIdException("Illegal amount of annotated id properties of class " + entity.getClass().getName());
			} else {
				ClassUtil.setSilent(result, fields.get(0).getName(), id);
			}
		}
		return result;
	}
244814
def -(other)
      records = @records.clone.reject { |name, records| other.records.include?(name) }
      SearchAtom.new(records)
    end
141818
function findEntity(collection, entity) {
	return collection.findIndex(item => angular.equals(item, entity));
}
507487
def query(self, search, query):
        
        if query:
            if self.fields:
                return search.query('multi_match', fields=self.fields, query=query)
            else:
                return search.query('multi_match', query=query)
        return search
359817
def search(self, **kw):
        """"""
        q = db.select(self.table).condition('status', 'active')
        for k, v in kw:
            q.condition(k, v)
        data = q.execute()
        users = []
        for user in data:
            users.append(self.load(user, self.model))
        return users
1228741
@Override
    public EntityIdentifier[] searchForEntities(
            String query, IGroupConstants.SearchMethod method, Class type) throws GroupsException {
        Set allIds = new HashSet();

        for (Iterator services = getComponentServices().values().iterator(); services.hasNext(); ) {
            IIndividualGroupService service = (IIndividualGroupService) services.next();
            EntityIdentifier[] ids = service.searchForEntities(query, method, type);
            for (int i = 0; i < ids.length; i++) {
                allIds.add(ids[i]);
            }
        }
        return (EntityIdentifier[]) allIds.toArray(new EntityIdentifier[allIds.size()]);
    }
949711
def find_entity(self, x):
        

        qstr = self.prefixes + """
            SELECT ?x WHERE {{
                ?x rn:hasName "{0}" .
            }}
            """.format(x)
        res = self.graph.query(qstr)
        if list(res):
            en = list(res)[0][0].toPython()
            return en
        else:
            return None
300402
def fetch_search_document(self, *, index):
        """"""
        assert self.pk, "Object must have a primary key before being indexed."
        client = get_client()
        return client.get(index=index, doc_type=self.search_doc_type, id=self.pk)