Programing

Google App Engine : Gql LIKE 쿼리를 수행 할 수 있습니까?

lottogame 2020. 7. 13. 08:08
반응형

Google App Engine : Gql LIKE 쿼리를 수행 할 수 있습니까?


정말 간단합니다. SQL에서 텍스트 필드에서 두 문자를 검색하려면 다음을 수행하십시오.

SELECT blah FROM blah WHERE blah LIKE '%text%'

App Engine 설명서에는이를 달성하는 방법에 대한 언급이 없지만 분명히 일반적인 문제입니까?


App Engine의 데이터베이스 백엔드 인 BigTable은 수백만 레코드로 확장됩니다. 이로 인해 App Engine에서는 테이블이 잘 채워진 테이블의 경우 성능이 저하되므로 테이블 스캔을 수행하는 쿼리를 수행 할 수 없습니다.

즉, 모든 쿼리는 인덱스를 사용해야합니다. 이 경우에만 할 수있는 이유 =, >그리고 <쿼리. (실제로 할 수도 !=있지만 API는 조합 ><쿼리를 사용하여이 작업을 수행 합니다.) 또한 개발 환경에서 수행하는 모든 쿼리를 모니터링하고 누락 된 인덱스를 index.yaml파일에 자동으로 추가 합니다.

LIKE검색어 를 색인 할 수있는 방법이 없으므로 사용할 수 없습니다.

이에 대한 더 좋고 자세한 설명을 보려면 이 Google IO 세션시청 하십시오.


나는 같은 문제에 직면하고 있지만 Google 앱 엔진 페이지에서 무언가를 발견했습니다.

팁 : 쿼리 필터에는 문자열 값의 일부만 일치시키는 명시적인 방법이 없지만 불평등 필터를 사용하여 접두사 일치를 위조 할 수 있습니다.

db.GqlQuery("SELECT * FROM MyModel WHERE prop >= :1 AND prop < :2",
            "abc",
            u"abc" + u"\ufffd")

이것은 모든 MyModel 엔터티를 abc 문자로 시작하는 문자열 속성 소품과 일치시킵니다. 유니 코드 문자열 u "\ ufffd"는 가능한 최대 유니 코드 문자를 나타냅니다. 속성 값이 인덱스에서 정렬 될 때이 범위에 속하는 값은 주어진 접두사로 시작하는 모든 값입니다.

http://code.google.com/appengine/docs/python/datastore/queriesandindexes.html

어쩌면 이것은 트릭을 할 수 있습니다.)


전체 App Engine은 LIKE 쿼리를 지원하지 않으므로 ListPropertyStringListProperty 속성을 살펴보십시오 . 이러한 속성에 대해 동등성 테스트를 수행하면 테스트가 실제로 모든 목록 멤버에 적용됩니다 (예 : list_property = value값이 목록의 아무 곳에 나 나타나는지 테스트).

때때로이 기능은 LIKE 쿼리가없는 문제를 해결하는 방법으로 사용될 수 있습니다. 예를 들어이 게시물에 설명 된대로 간단한 텍스트 검색 을 수행 할 수 있습니다 .


SQL과 유사한 전체 텍스트 검색 쿼리를 수행 하려면 검색 서비스 를 사용해야 합니다 LIKE.

Gaelyk 은보다 사용자 친화적 인 검색어 를 수행하기 위해 도메인 별 언어를 제공 합니다 . 예를 들어 다음 코드 조각은 제목이 포함 fern된 장르와 정확히 일치하는 장르를 가진 최신 책에서 정렬 된 처음 10 권의 책을 찾습니다 thriller.

def documents = search.search {
    select all from books
    sort desc by published, SearchApiLimits.MINIMUM_DATE_VALUE
    where title =~ 'fern'
    and genre =  'thriller'
    limit 10
}

Groovy의 일치 연산자로 작성되었습니다 =~. distance(geopoint(lat, lon), location)뿐만 아니라 같은 기능을 지원합니다 .


App Engine은 데이터 저장소를 지원하는 버전 1.7.0에서 범용 전체 텍스트 검색 서비스시작했습니다 .

에 세부 발표 .

사용 방법에 대한 자세한 정보 : https://cloud.google.com/appengine/training/fts_intro/lesson2


객관화에서보세요 여기에 , 그것은 데이터 저장소 액세스 API 같다. 이 질문에 대한 FAQ가 있습니다. 여기에 답이 있습니다.

유사 쿼리를 수행하는 방법 (LIKE "foo %")
저장 및 검색시 순서를 반대로 바꾸면 startWith 또는 endWith와 같은 작업을 수행 할 수 있습니다. 원하는 시작 값과 원하는 값 바로 위의 범위 쿼리를 수행합니다.

String start = "foo";
    ... = ofy.query(MyEntity.class).filter("field >=", start).filter("field <", start + "\uFFFD");

Just follow here: init.py#354">http://code.google.com/p/googleappengine/source/browse/trunk/python/google/appengine/ext/search/init.py#354

It works!

class Article(search.SearchableModel):
    text = db.TextProperty()
    ...

  article = Article(text=...)
  article.save()

To search the full text index, use the SearchableModel.all() method to get an
instance of SearchableModel.Query, which subclasses db.Query. Use its search()
method to provide a search query, in addition to any other filters or sort
orders, e.g.:

  query = article.all().search('a search query').filter(...).order(...)

I tested this with GAE Datastore low-level Java API. Me and works perfectly

    Query q = new Query(Directorio.class.getSimpleName());

    Filter filterNombreGreater = new FilterPredicate("nombre", FilterOperator.GREATER_THAN_OR_EQUAL, query);
    Filter filterNombreLess = new FilterPredicate("nombre", FilterOperator.LESS_THAN, query+"\uFFFD");
    Filter filterNombre =  CompositeFilterOperator.and(filterNombreGreater, filterNombreLess);

    q.setFilter(filter);

In general, even though this is an old post, a way to produce a 'LIKE' or 'ILIKE' is to gather all results from a '>=' query, then loop results in python (or Java) for elements containing what you're looking for.

Let's say you want to filter users given a q='luigi'

users = []
qry = self.user_model.query(ndb.OR(self.user_model.name >= q.lower(),self.user_model.email >= q.lower(),self.user_model.username >= q.lower()))

for _qry in qry:
 if q.lower() in _qry.name.lower() or q.lower() in _qry.email.lower() or q.lower() in _qry.username.lower():
      users.append(_qry)

It is not possible to do a LIKE search on datastore app engine, how ever creating an Arraylist would do the trick if you need to search a word in a string.

@Index
    public ArrayList<String> searchName;

and then to search in the index using objectify.

List<Profiles> list1 = ofy().load().type(Profiles.class).filter("searchName =",search).list();

and this will give you a list with all the items that contain the world you did on the search


If the LIKE '%text%' always compares to a word or a few (think permutations) and your data changes slowly (slowly means that it's not prohibitively expensive - both price-wise and performance-wise - to create and updates indexes) then Relation Index Entity (RIE) may be the answer.

Yes, you will have to build additional datastore entity and populate it appropriately. Yes, there are some constraints that you will have to play around (one is 5000 limit on the length of list property in GAE datastore). But the resulting searches are lightning fast.

For details see my RIE with Java and Ojbectify and RIE with Python posts.


"Like" is often uses as a poor-man's substitute for text search. For text search, it is possible to use Whoosh-AppEngine.

참고URL : https://stackoverflow.com/questions/47786/google-app-engine-is-it-possible-to-do-a-gql-like-query

반응형