答案 0 :(得分:1)
要创建搜索索引,您需要创建一个"视图"。这里有很好的解释:http://guide.couchdb.org/editions/1/en/views.html
你可以从Futon那里做到,但你应该先用一个小数据集来练习。
答案 1 :(得分:1)
我正在寻找的解决方案基于this library。
{ “CouchDB的-lucene” 的: “欢迎”, “版本”: “1.1.0-快照”}
要使其运行,我必须使用mvn在根目录中构建它,然后导航到目标并在解压缩的couchdb-lucene中运行命令 ./ bin / run :
root@mario-VirtualBox:/home/mario/CouchDB_mario/couchdb-lucene/target/couchdb-lucene-1.1.0-SNAPSHOT# ./bin/run
您需要拥有以下所有代码:
[httpd_global_handlers]
_fti = {couch_httpd_proxy, handle_proxy_req, <<"http://localhost:5985">>}
多亏了这一点,我终于可以使用Apache Lucene索引来查询CouchDB。
curl -X PUT http://localhost:5984/user14169_slovnik_medical/_design/medical -d @user14169_slovnik_medical.json
JSON设计文档如下所示:
{
"_id": "_design/medical",
"fulltext": {
"by_meaning": {
"index": "function(doc) { var ret=new Document(); ret.add(doc.vyznam); return ret }"
},
"by_shortcut": {
"index": "function(doc) { var ret=new Document(); ret.add(doc.zkratka); return ret }"
}
}
}
{ "_id": "63e5c848fa2211c3b063d6feccd3d942", "_rev": "1-899a6924ed08097b1a37e497d91726fd", "DATAWORKS_DOCUMENT_TYPE": "user14169_slovnik_medical", "vyznam": "End to side", "zkratka": "e-t-s" }
然后您很容易实现这样的查询:
http://localhost:5984/_fti/local/user14169_slovnik_medical/_design/medical/by_meaning?q=lob~
本地前缀是因为我在1个节点上的localhost上运行数据库,默认情况下couchdb-lucene连接到localhost。
最酷的是,您可以在Java中使用客户端API org.lightcouch jar库并执行一些简单的调用:
CouchDbClient dbClient = new CouchDbClient("user14169_slovnik_medical", true, "http", "127.0.0.1", 5984, null, null);
String uriFullText = dbClient.getBaseUri() + "_fti/local/user14169_slovnik_medical/_design/medical/by_shortcut?q=lob*";
JsonObject result = dbClient.findAny(JsonObject.class, uriFullText);
System.out.println(result.toString());
答案 2 :(得分:0)
你不能。搜索是Cloudant功能,不在CouchDB的任何当前版本中。