# install java JRE (so solr can run)
[entadmin@dev3 equeuelib]$ sudo yum install java-1.8.0-openjdk
# enable it in riak.conf: search=on
# reload/restart riak as needed
#create index (can also be done via PHP)
[aesteban@localhost ansible]$ curl -X PUT riak.example.com:8098/search/index/story_index
# associate index to bucket (can also be done via PHP)
[aesteban@localhost ansible]$ curl -X PUT riak.example.com:8098/buckets/story/props -H'content-type:application/json' -d'{"props":{"search_index":"story_index"}}'
# verify it by viewing bucket props, search for 'search_index'
riak.example.com:8098/buckets/story/props
# add indexable fields to a Story object per se
eg: authorId_i and publicationDate_dt
# query it !
riak.example.com:8098/search/query/story_index?wt=json&q=authorId_i:8144
# it returns all story keys associated with that author.
# looks like there's sort capabilities available too:
riak.example.com:8098/search/query/story_index?wt=json&q=authorId_i:8144&sort=publicationDate_dt%20desc
# by default it seems to put a limit of 10 rows, we can change that...
riak.example.com:8098/search/query/story_index?wt=json&q=authorId_i:8144&sort=publicationDate_dt%20desc&rows=50
# Solr dashboard riak.example.com:8093/internal_solr/#/story_index
PHP
$indexes = [
[
"name" => "story_index",
"bucket" => "story"
]
];
$node = (new \Basho\Riak\Node\Builder)
->atHost('riak host')
->onPort('riak port'))
->build();
$riak = new \Basho\Riak ([$node]);
foreach ($indexes as $index)
{
// creates index
$response = (new \Basho\Riak\Command\Builder\Search\StoreIndex($riak))
->withName( $index['name'] )
->usingSchema('_yz_default')
->build()
->execute();
// associates index with bucket
(new \Basho\Riak\Command\Builder\Search\AssociateIndex($riak))
->withName( $index['name'] )
->buildBucket($index['bucket'])
->build()
->execute();
}
Docs:
http://docs.basho.com/riak/kv/2.2.3/dev ... ge/search/
https://docs.riak.com/riak/kv/latest/developing/usage/search/index.html
Default schema:
https://raw.githubusercontent.com/basho/yokozuna/develop/priv/default_schema.xml
12/7/2020
Sample query
$query = [
// "defType" => "edismax", // query parser
"sort" => "score DESC", // override default score sorting
"q" => "{!edismax}{$parameters['phrase']}", // query
"qf" => "authorName^6 objectId^4 headline^2 deck", // query fields
"fq" => "{!lucene}
edition:{$parameters['edition']}
AND statusId:4
AND objectTypeId:(1 2 4 12 15)
AND publicationDateISO8601:[NOW-10YEAR TO NOW]", // filter query
"qs" => "5", // query phrase slop
"bq" => "publicationDateISO8601:[NOW-2YEAR TO NOW]", // boost query
"fl" => "*,score", // field list
"hl" => "true", // highlight
"mm" => "3<80%", // minimum match
"wt" => "json", // response writer
"rows" => $rows, // rows
"start" => $start, // offset
// spell check parameters
"df" => "entspellcheck",
"spellcheck" => "true" ,
"spellcheck.q" => "\"{$parameters['phrase']}\"~10" , // proximity added
// "spellcheck.build" => "true" ,
"spellcheck.collate" => "true" ,
"spellcheck.maxCollations" => "30" ,
"spellcheck.maxCollationTries" => "30" ,
"spellcheck.maxCollationEvaluations" => "30" ,
"spellcheck.collateExtendedResults" => "true" ,
"spellcheck.collateMaxCollectDocs" => "30" ,
"spellcheck.count" => "10" ,
// "spellcheck.dictionary" => 'wordbreak' ,
"spellcheck.extendedResults" => "true" ,
// "spellcheck.onlyMorePopular" => "true" ,
"spellcheck.maxResultsForSuggest" => "5" ,
"spellcheck.alternativeTermCount" => "10" ,
// "spellcheck.reload" => "true",
"spellcheck.accuracy" => "0.5" ,
];
Which will be something like this:
http://app01.example.com:8098/search/query/article_index?sort=score DESC
&q={!edismax}how to become a millionaire
&qf=authorName^6 objectId^4 headline^2 deck
&fq={!lucene}
edition:us
AND statusId:4
AND objectTypeId:(1 2 4 12 15)
AND publicationDateISO8601:[NOW-10YEAR TO NOW]
&qs=5
&bq=publicationDateISO8601:[NOW-2YEAR TO NOW]
&fl=*,score
&hl=true
&mm=3<80%
&wt=json
&rows=20
&start=0
&df=entspellcheck
&spellcheck=true
&spellcheck.q="how to become a millionaire"~10
&spellcheck.collate=true
&spellcheck.maxCollations=30
&spellcheck.maxCollationTries=30
&spellcheck.maxCollationEvaluations=30
&spellcheck.collateExtendedResults=true
&spellcheck.collateMaxCollectDocs=30
&spellcheck.count=10
&spellcheck.extendedResults=true
&spellcheck.maxResultsForSuggest=5
&spellcheck.alternativeTermCount=10
&spellcheck.accuracy=0.5
[ view entry ] ( 857 views ) | print article
<<First <Back | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | Next> Last>>