代码之家  ›  专栏  ›  技术社区  ›  Omar Jandali

检查JSON对象值是否包含短语-django[duplicate]

  •  0
  • Omar Jandali  · 技术社区  · 7 年前

    我有一个django项目。我在这个项目中安装了Firebase。Firebase创建并返回JSON格式的对象。现在,我想有一个搜索系统,通过现有用户返回一个对象,其中包含列表中存储的所有用户名值,然后显示所有结果。

    OrderedDict([  
       ('info',
       {  
          'bio':'jogn from the office',
          'company':'MySplit',
          'dob':'1993-03-23',
          'first_name':'jim',
          'gender':'M',
          'last_name':'helpert',
          'phone':'+19515394856'
       }   ),
       ('location',
       {  
          'city':'Mis Viejo',
          'state':'CA',
          'street':'27806 cheller',
          'zip_code':98892
       }   ),
       ('status',
       {  
          'active':'1',
          'group':'dev',
          'premium':'1'
       }   ),
       ('username',
       'jimhelpert'   )
    ])
    

    我想搜索并返回一个包含所有用户名的对象 jim

    我找不到如何进行查询,将返回用户名包含短语的所有对象。。。

    以下是view.py:

            user_id = request.session['uid']
            user_profile = database.child('users').child(user_id).child('profile').get()
            print(user_profile.key())
            print(user_profile.val())
            print(user_profile)
            print(type(user_profile))
            parameters = {
                'user_profile':user_profile.val(),
            }
            return render(request, 'users/user_home.html', parameters)
    
    1 回复  |  直到 7 年前
        1
  •  0
  •   Daniel Hepper    7 年前

    这里是什么 Firebase documentation 关于搜索:

    CloudFireStore不支持本机索引或搜索文本字段 在文件中。

    它接着说:

    此外,下载整个集合以在客户端搜索字段也不切实际。

    不过,我支持文档中的建议,即使用专用搜索服务。

    要启用对云Firestore数据的全文搜索,请使用第三方搜索服务,如Algolia。

    或者,您可以考虑使用允许这种查询的SQL数据库。