我正在尝试实现给定any JSONObject和path 的函数,该函数String将返回与该路径对应的对象属性。
例如,给定以下json:
{
"name": "John",
"friends": [
{"name": "Paul",
"age":42},
{"name": "Peter",
"age":24}
],
"address": {"city": "London"}
}
Run Code Online (Sandbox Code Playgroud)
getAttribute(jsonObject, "name") 应该回来 "John"getAttribute(jsonObject, "address.city") 应该回来 "London"getAttribute(jsonObject, "friends[0].name") 应该回来 "Paul"请注意,此JSON只是一个示例,jsonObject没有预定义的结构,可以表示任何有效的json。
我编写了实现前两种情况的第一个版本,但是处理数组和多级数组"foo[0][0].bar"给此函数带来了很多复杂性。
我正在将Java Android项目转换为Kotlin.
我正在使用API.AI的客户端,它有两个AIConfiguration类:
超
package ai.api;
public class AIConfiguration implements Cloneable {
public static enum SupportedLanguages {
English("en"),
//...
}
//...
}
Run Code Online (Sandbox Code Playgroud)
子类
package ai.api.android;
public class AIConfiguration extends ai.api.AIConfiguration {
public enum RecognitionEngine {
//...
}
Run Code Online (Sandbox Code Playgroud)
在我的Java代码中,我正在创建子类的实例,如api指南中所建议的那样:
final AIConfiguration config = new AIConfiguration("TOKEN",
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System);
Run Code Online (Sandbox Code Playgroud)
一旦转换为Kotlin,它看起来像这样:
val config = AIConfiguration("TOKEN",
AIConfiguration.SupportedLanguages.English,
AIConfiguration.RecognitionEngine.System)
Run Code Online (Sandbox Code Playgroud)
...导致一个Unresolved reference: SupportedLanguages.
ai.api.AIConfiguration.SupportedLanguages.English成功编译的引用.import ai.api.AIConfiguration as SuperAIConfiguration和导入超类SuperAIConfiguration.SupportedLanguages,但我宁愿直接在子类上引用枚举.我不明白:为什么这个引用在Java中有效但在Kotlin中没有?
我正在使用Algolia的InstantSearch Android库.
这是我的查询:
searcher.setQuery(new Query().setAroundLatLngViaIP(true).setAroundRadius(5000)).
Run Code Online (Sandbox Code Playgroud)
但是当我移动地图时,标记会保留在原位.移动地图位置视图时,如何在地图上显示新标记?
在我的Android应用中,我使用Firebase作为数据库.我想添加一些搜索功能,经过我的研究,我发现Algolia适合我.
Algolia的Firebase教程解释了如何将我现有的Firebase数据库与Algolia集成.在本教程中,它们提供了一些Node.js代码(我不熟悉).在第一次收集数据时,我只是复制了集成代码,进行了必要的更改并在Windows终端上运行:数据现在从Firebase导入到Algolia.
但是还有一些其他必要的规范,如更新,删除数据.他们还为此目的提供了一些js代码,但我真的不知道如何使用这个js代码在我的Android应用程序中附加这些监听器.
任何人都可以告诉我它是如何正确完成的?
我创建了一个应用程序,任何人都可以销售产品:您设置其详细信息然后我将其保存在Firebase中.
在客户端(Android应用程序)我希望能够使用纯文本搜索产品.
我认为最好的方法是使用Algolia,但我真的不知道如何设置它.我们将不胜感激!
我正在尝试使用Algolia在我的Android应用中执行过滤,因为他们已经在他们的Filtering和facets教程中显示但是我在我的query.setFilters()方法中收到此错误:Algolia exception filters: Unexpected token string(to) expected ')'
这是我使用的代码示例:
Query query = new Query();
query.setAttributesToHighlight("type");
query.setHighlightPreTag("<p style=\"color:red\">");
query.setHighlightPostTag("</p>");
query.setRestrictSearchableAttributes("type","price");
query.setFilters("code=1 AND (price:1000 to 300000000 OR price:10 to 100)");
Run Code Online (Sandbox Code Playgroud)
我的目标是对我的数据进行范围搜索.我怎样才能实现这一目标?
我在使用Algolia Django与我的一个包含TaggitManager()字段的模型集成时遇到了一些问题.我正在运行此命令时抛出以下错误:
$ python manage.py algolia_reindex
AttributeError: '_TaggableManager' object has no attribute 'name'
Run Code Online (Sandbox Code Playgroud)
我已经看过Taggit文档,但我不确定如何将Algolia搜索索引方法概述的方法结合起来.
index.py:
import django
django.setup()
from algoliasearch_django import AlgoliaIndex
class BlogPostIndex(AlgoliaIndex):
fields = ('title')
settings = {'searchableAttributes': ['title']}
index_name = 'blog_post_index'
Run Code Online (Sandbox Code Playgroud)
models.py:
from taggit.managers import TaggableManager
class Post(models.Model):
...some model fields...
tags = TaggableManager()
Run Code Online (Sandbox Code Playgroud) 我正在使用带有Scout的Laravel 5.5.我在algolia中有一个索引,使用Documents和与这些文档相关的用户
class Documents extends Model
{
use Searchable;
public function toSearchableArray()
{
$data = $this->toArray();
// formatting relationship for algolia
$data['users'] = $this->types->toArray();
$data['document_type'] = $this->typeDocuments->name;
return $data;
}
protected $fillable = array('name', 'description', 'document_type');
public function types() {
return $this->belongsToMany('App\Users', 'document_rights', 'user_id', 'id');
}
public function typeDocuments() {
return $this->belongsTo('App\Document_type', 'document_type');
}
}
Run Code Online (Sandbox Code Playgroud)
就我而言,我会在一天内更新用户名,如下所示:
public function update(Request $request)
{
$user = Users::find(5);
$user->name = 'jean floriot';
$user->update();
}
Run Code Online (Sandbox Code Playgroud)
但它永远不会改变Algolia索引中的用户.任何想法如何进行?
当我使用InstantSearch Android时,会出现内存泄漏.
请参阅以下MainActivity泄漏内存... hprof显示它是一个问题com.algolia.instantsearch.ui.views.Hits.什么人知道如何在被摧毁时摧毁那个视图Activity?
public class MainActivity extends AppCompatActivity {
private Searcher searcher;
InstantSearch helper;
Hits hits;
LinearLayout activity_main;
@Override
protected void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_main);
hits= (Hits) findViewById(R.id.hits);
activity_main= (LinearLayout) findViewById(R.id.activity_main);
searcher = Searcher.create("app_id","secret_key","Items");
helper = new InstantSearch(this, searcher);
helper.search();
}
@Override
protected void onDestroy() {
searcher=null;
helper=null;
hits.clear();
hits.removeAllViewsInLayout();
hits.removeAllViews();
hits.destroyDrawingCache();
hits.setBackground(null);
hits.setBackgroundResource(0);
hits=null;
activity_main.removeAllViewsInLayout();
activity_main.removeAllViews();
activity_main.destroyDrawingCache();
activity_main.setBackground(null);
activity_main.setBackgroundResource(0);
activity_main=null;
Log.i("AppInfo","Destroy");
super.onDestroy();
}
}
Run Code Online (Sandbox Code Playgroud)
这是我的activity_main.xml:
<LinearLayout
android:id="@+id/activity_main"
xmlns:android="http://schemas.android.com/apk/res/android" …Run Code Online (Sandbox Code Playgroud) 我们有几十个索引,每个索引约有2.5k条记录。现在,排名和排序是我们无法回避的事情。在大多数情况下,它可以按预期工作,但是有些记录对我们没有意义。
搜索词:i 16(16之前的空格)
结果是:
最相关的结果是最后的结果。虽然我知道前两个是由于这两个而出现的16,但我不明白为什么中间的其余部分要高于实际的,最相关的那些。
我们不能将ASC更改为DESC,因为那样会搞乱其余的搜索,这很好。
另外,我们不确定这意味着什么,因为我们在填充新数据之前先清除了索引。
以下是设置的一些屏幕截图:
谁能为我们解决这个谜?