2016-11-16 3 views
1

Я настраиваю Solr в облачном режиме и хочу настроить настраиваемый пользовательский парсер. , чтобы настроить его. Я использую скрипт PowerShell следующим образом.Как настроить Solr Custom Query Parser?

# Variables ########### 
$hostName = 'localhost' 
$port = 8983 
$numberOfShards = 1 
$replicationFactor = 1 

# These should be picked from an external file 
$collections = 'Collection1', 'Collection2', 'Collection3', 'Collection4', 'Collection5', 'Collection6', 'Collection7', 'Collection8', 'Collection9'; 
####################### 

# Following 3 commands needs file system access and can be extracted out of this script in case we want to use already hosted Solr instance on cloud 
# Start Solr in Cloud Mode 
'####### Starting Solr #######'; 
..\bin\solr start -c -h $hostName -p $port "-Denable.runtime.lib=true" 

# Upload configuration to ZooKeeper 
# We need to upload multiple copies of the configuration to the ZooKeeper one for each collection, so each collection can have it's different schema 
$zooKeeperPort = $port + 1000; 
foreach ($c in $collections) { 
    $configName = $c + 'SearchConfig'; 
    '####### Uploading Config to ZooKeeper for collection {0} #######' -f $c; 
    $configPath = './xuber_basic_config/conf/'; 
    ..\server\scripts\cloud-scripts\zkcli.bat -zkhost localhost:$zooKeeperPort -cmd upconfig -confdir $configPath -confname $configName; 
} 

$urlPrefix = 'http://' + $hostName + ':' + $port + '/solr'; 

function PostToSolr 
{ 
    'HTTP POST: {0}' -f $args[0]; 
    Invoke-WebRequest -uri $args[0] -Method POST -ContentType "application/json" -Body $args[1]; 
} 

function GetToSolr 
{ 
    'HTTP GET: {0}' -f $args[0]; 
    Invoke-WebRequest -uri $args[0] -Method GET -ContentType "application/json"; 
} 

function PostSchema 
{ 
    $schemaFileName = $args[0]; 
    $url = $args[1]; 
    $jsonToPost = Get-Content ./$schemaFileName; 
    PostToSolr $url $jsonToPost; 
} 

# Get a list of collections already present in Solr 
$readCollectionUrl = $urlPrefix + '/admin/collections?action=LIST&wt=json'; 
$alreadyExistingCollections = ((GetToSolr $readCollectionUrl).Content | ConvertFrom-Json).collections; 

# Create .system collection 
$systemCollectionName = '.system'; 
If ($alreadyExistingCollections -contains $systemCollectionName) { 
    $deleteCollectionUrl = $urlPrefix + '/admin/collections?action=DELETE&name={0}' -f $systemCollectionName; 
    GetToSolr $deleteCollectionUrl; 
} 

$addSystemCollectionPath = $urlPrefix + '/admin/collections?action=CREATE&name=' + $systemCollectionName; 
GetToSolr $addSystemCollectionPath; 

$dataSecurityPlugin = 'customQueryPlugin'; 
$addBlobPath = $urlPrefix + '/'+ $systemCollectionName + '/blob/' + $dataSecurityPlugin; 
'HTTP POST: {0}' -f $addBlobPath; 
Invoke-WebRequest -uri $addBlobPath -Method Post -InFile .\customQueryPlugin.jar -ContentType application/octet-stream; 

$createCollectionPrefix = $urlPrefix + '/admin/collections?action=CREATE&name={0}&numShards={1}&replicationFactor={2}&collection.configName={3}'; 
$schemaApiUrlPrefix = $urlPrefix + '/{0}/schema'; 

# Create Solr Collections 
foreach ($c in $collections) { 
    # Check to see if the collection already exists, if yes, delete it. 
    If ($alreadyExistingCollections -contains $c) { 
     '####### Collection {0} already present hence deleting it #######' -f $c 
     $deleteCollectionUrl = $urlPrefix + '/admin/collections?action=DELETE&name={0}' -f $c; 
     GetToSolr $deleteCollectionUrl; 
    } 

    '####### Creating collection {0} #######' -f $c; 
    $configName = $c + 'SearchConfig'; 
    $tempPath = $createCollectionPrefix -f $c,$numberOfShards,$replicationFactor,$configName; 
    GetToSolr $tempPath; 

    # Add data security plugin to runtime 
    $addToRuntimePath = $urlPrefix + '/'+ $c + '/config'; 
    $runtimeJsonData = @{"add-runtimelib" = @{name = "customQueryPlugin"; version = 1}} | ConvertTo-Json; 
    $runtimeJsonData; 
    PostToSolr $addToRuntimePath $runtimeJsonData; 

    $schemaAddUrl = $schemaApiUrlPrefix -f $c; 
    # Push the common Schema 
    '####### Adding common schema for collection {0} #######' -f $c; 
    $schemaFileName = 'Common_Schema.json'; 
    PostSchema $schemaFileName $schemaAddUrl; 

    # Push the Schema specific to the collection 
    '####### Adding specific schema for collection {0} #######' -f $c; 
    $schemaFileName = $c + '_Schema.json'; 
    PostSchema $schemaFileName $schemaAddUrl; 

    # Register QueryParser 
    $addQueryParserPath = $addToRuntimePath; 
    $addQueryParserData = @{"create-queryparser" = @{name = "acl"; runtimeLib = $true; class = "customQueryPlugin.customSearchQueryParser"}} | ConvertTo-Json; 
    PostToSolr $addQueryParserPath $addQueryParserData; 
} 

Я использую edismax, и возможность поиска мои данные без фильтра запроса , но с фильтром запроса он не дает каких-либо данных, вы можете сказать, если я что-то не хватает ??

ответ

0

Я думаю, что ключ находится в последних строках вашего сценария:

$addQueryParserData = @{"create-queryparser" = @{name = "acl"; runtimeLib = $true; class = "customQueryPlugin.customSearchQueryParser"}} | ConvertTo-Json; 

Вы уверены, что у вас есть $true переменные: runtimeLib = $true? Держу пари, это должно быть довольно runtimeLib = true.

Также следует упомянуть имя вашего класса Parser: class = "customQueryPlugin.customSearchQueryParser". Пожалуйста, убедитесь, что у вашего customQueryPlugin.jar есть его как полное имя.

+0

$ true - вещь powershell, так как она не понимает истину, также проверили имя плагина. –

+0

Есть ли выходные данные после запуска этого скрипта? Любые ошибки/исключения? –