forked from KnpLabs/KnpBundles
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
26 changed files
with
6,111 additions
and
77 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
wget http://www.idg.pl/mirrors/apache/lucene/solr/3.6.0/apache-solr-3.6.0.tgz | ||
tar -zxvf apache-solr-3.6.0.tgz | ||
mv apache-solr-3.6.0 apache-solr | ||
php app/console --env=test kb:solr:start --solr-path="`pwd`/apache-solr/example/" |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
118 changes: 118 additions & 0 deletions
118
src/Knp/Bundle/KnpBundlesBundle/Command/KbSolrServerStartCommand.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,118 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\KnpBundlesBundle\Command; | ||
|
||
use Symfony\Bundle\FrameworkBundle\Command\ContainerAwareCommand; | ||
use Symfony\Component\Console\Input\InputInterface; | ||
use Symfony\Component\Console\Input\InputOption; | ||
use Symfony\Component\Console\Input\InputArgument; | ||
use Symfony\Component\Console\Output\OutputInterface; | ||
use Symfony\Component\Process\Process; | ||
|
||
/** | ||
* @author Leszek Prabucki <leszek.prabucki@gmail.com> | ||
*/ | ||
class KbSolrServerStartCommand extends ContainerAwareCommand | ||
{ | ||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function configure() | ||
{ | ||
$this | ||
->setName('kb:solr:start') | ||
->setDescription('Start SOLR for given enviroment') | ||
->addOption('solr-path', 'p', InputOption::VALUE_OPTIONAL, 'path to solr (where start.jar is localized)', '/opt/solr/example') | ||
->addOption('show-commands-only', null, InputOption::VALUE_NONE, 'If set show command but not execute it') | ||
; | ||
} | ||
|
||
/** | ||
* {@inheritdoc} | ||
*/ | ||
protected function execute(InputInterface $input, OutputInterface $output) | ||
{ | ||
if ($input->getOption('show-commands-only')) { | ||
$output->writeln(sprintf('<info>%s</info>', $this->createRunSolrCommand($input))); | ||
|
||
return 0; | ||
} | ||
|
||
if ($this->solrIsRunning()) { | ||
$output->writeln(sprintf('<info>%s %d</info>', 'Solr is running. Pid: ', $this->getSolrPid())); | ||
|
||
return 0; | ||
} | ||
|
||
$output->writeln(sprintf('<info>%s</info>', 'Starting solr in background process')); | ||
|
||
$process = new Process($this->createRunSolrCommand($input)); | ||
$process->run(); | ||
|
||
$output->writeln(sprintf('<info>Pid: %d</info>', $this->getSolrPid())); | ||
} | ||
|
||
/** | ||
* @return boolean | ||
*/ | ||
private function solrIsRunning() | ||
{ | ||
return (boolean) $this->getSolrPid(); | ||
} | ||
|
||
/** | ||
* Get SOLR pid | ||
*/ | ||
private function getSolrPid() | ||
{ | ||
$properties = array(); | ||
foreach ($this->getPropertiesArray() as $key => $property) { | ||
$properties[] = $key.'='.$property; | ||
} | ||
|
||
$process = new Process(sprintf('ps aux | grep \\\\%s | grep -v grep | awk \'{ print $2 }\'', implode('| grep \\\\', $properties))); | ||
$process->run(); | ||
$pid = $process->getOutput(); | ||
|
||
return (integer) $pid; | ||
} | ||
|
||
/** | ||
* Create and return SOLR start command | ||
* | ||
* @param InputInterface $input | ||
* @return string | ||
*/ | ||
private function createRunSolrCommand(InputInterface $input) | ||
{ | ||
$solrPath = $input->getOption('solr-path'); | ||
|
||
return sprintf('(cd %s; java -jar %s start.jar ) 1> /dev/null 2> /dev/null &', $solrPath, $this->buildProperties()); | ||
} | ||
|
||
/** | ||
* Build SOLR start.jar properties | ||
* | ||
* @return string | ||
*/ | ||
private function buildProperties() | ||
{ | ||
$properties = array(); | ||
foreach ($this->getPropertiesArray() as $key => $property) { | ||
$properties[] = $key.'='.$property; | ||
} | ||
|
||
return implode(' ', $properties); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
private function getPropertiesArray() | ||
{ | ||
return array( | ||
'-Djetty.port' => $this->getContainer()->get('solarium.client')->getAdapter()->getPort(), | ||
'-Dsolr.solr.home' => $this->getContainer()->get('kernel')->getBundle('KnpBundlesBundle')->getPath().'/Resources/solr' | ||
); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
45 changes: 45 additions & 0 deletions
45
src/Knp/Bundle/KnpBundlesBundle/Features/Context/SolrContext.php
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
<?php | ||
|
||
namespace Knp\Bundle\KnpBundlesBundle\Features\Context; | ||
|
||
use Behat\BehatBundle\Context\BehatContext; | ||
|
||
require_once 'PHPUnit/Autoload.php'; | ||
require_once 'PHPUnit/Framework/Assert/Functions.php'; | ||
|
||
/** | ||
* Solr context. | ||
*/ | ||
class SolrContext extends BehatContext | ||
{ | ||
/** | ||
* @Given /^bundles are indexed$/ | ||
*/ | ||
public function bundlesAreIndexed() | ||
{ | ||
$this->solrIsEnabled(); | ||
$bundles = $this->getContainer()->get('doctrine')->getRepository('Knp\\Bundle\\KnpBundlesBundle\\Entity\\Bundle')->findAll(); | ||
|
||
$indexer = $this->getContainer()->get('knp_bundles.indexer.solr'); | ||
$indexer->deleteBundlesIndexes(); | ||
foreach ($bundles as $bundle) { | ||
$indexer->indexBundle($bundle); | ||
} | ||
} | ||
|
||
/** | ||
* @throw Solr HTTP error | ||
*/ | ||
protected function solrIsEnabled() | ||
{ | ||
$client = $this->getSolariumClient(); | ||
$query = $client->createPing(); | ||
|
||
$client->ping($query); | ||
} | ||
|
||
protected function getSolariumClient() | ||
{ | ||
return $this->getContainer()->get('solarium.client'); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
31 changes: 31 additions & 0 deletions
31
src/Knp/Bundle/KnpBundlesBundle/Resources/solr/conf/admin-extra.html
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<!-- The content of this page will be statically included into the top | ||
of the admin page. Uncomment this as an example to see there the content | ||
will show up. | ||
<hr> | ||
<i>This line will appear before the first table</i> | ||
<tr> | ||
<td colspan="2"> | ||
This row will be appended to the end of the first table | ||
</td> | ||
</tr> | ||
<hr> | ||
--> |
36 changes: 36 additions & 0 deletions
36
src/Knp/Bundle/KnpBundlesBundle/Resources/solr/conf/elevate.xml
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
<?xml version="1.0" encoding="UTF-8" ?> | ||
<!-- | ||
Licensed to the Apache Software Foundation (ASF) under one or more | ||
contributor license agreements. See the NOTICE file distributed with | ||
this work for additional information regarding copyright ownership. | ||
The ASF licenses this file to You under the Apache License, Version 2.0 | ||
(the "License"); you may not use this file except in compliance with | ||
the License. You may obtain a copy of the License at | ||
http://www.apache.org/licenses/LICENSE-2.0 | ||
Unless required by applicable law or agreed to in writing, software | ||
distributed under the License is distributed on an "AS IS" BASIS, | ||
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
See the License for the specific language governing permissions and | ||
limitations under the License. | ||
--> | ||
|
||
<!-- If this file is found in the config directory, it will only be | ||
loaded once at startup. If it is found in Solr's data | ||
directory, it will be re-loaded every commit. | ||
--> | ||
|
||
<elevate> | ||
<query text="foo bar"> | ||
<doc id="1" /> | ||
<doc id="2" /> | ||
<doc id="3" /> | ||
</query> | ||
|
||
<query text="ipod"> | ||
<doc id="MA147LL/A" /> <!-- put the actual ipod at the top --> | ||
<doc id="IW-02" exclude="true" /> <!-- exclude this cable --> | ||
</query> | ||
|
||
</elevate> |
Oops, something went wrong.