Skip to content

Commit

Permalink
0.10.4
Browse files Browse the repository at this point in the history
  • Loading branch information
ArtificialOwl committed Dec 3, 2016
1 parent 8acba3b commit 7db2f9f
Show file tree
Hide file tree
Showing 4 changed files with 136 additions and 16 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
**v0.10.3**
**v0.10.4**
- Upload/creating a .noindex file in a folder will prevent nextant to index its content (and subdirectories)
- --background will force the scan on next tick of the cron
- Live Index can use database instead of Semaphore
- bugfixes


**v0.10.2**
Expand Down
2 changes: 1 addition & 1 deletion appinfo/info.xml
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@


</description>
<version>0.10.3</version>
<version>0.10.4</version>
<licence>agpl</licence>
<author>Maxence Lange</author>
<types>
Expand Down
142 changes: 129 additions & 13 deletions lib/Service/SolrAdminService.php
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,12 @@ public function checkSchema($fix = false, &$ierror = '')
$changed = false;
while (true) {
foreach ($fields as $field) {
$this->solrService->message(' * Checking ' . $field['type'] . ' \'' . $field['data']['name'] . '\' : ', false);

if ($field['type'] === 'copy-field')
$this->solrService->message(' * Checking ' . $field['type'] . ' \'' . $field['data']['source'] . '/' . $field['data']['dest'] . '\' : ', false);
else
$this->solrService->message(' * Checking ' . $field['type'] . ' \'' . $field['data']['name'] . '\' : ', false);

if (self::checkFieldProperty($client, $field, $curr, $ierror))
$this->solrService->message('<info>ok</info>');
else {
Expand All @@ -100,7 +105,10 @@ public function checkSchema($fix = false, &$ierror = '')

if ($fix) {
$changed = true;
$this->solrService->message(' -> <comment>Fixing ' . $field['type'] . ' \'' . $field['data']['name'] . '\'</comment> ', false);
if ($field['type'] === 'copy-field')
$this->solrService->message(' -> <comment>Fixing ' . $field['type'] . ' \'' . $field['data']['source'] . '/' . $field['data']['dest'] . '\'</comment> ', false);
else
$this->solrService->message(' -> <comment>Fixing ' . $field['type'] . ' \'' . $field['data']['name'] . '\'</comment> ', false);

if ($curr) {
if (! self::modifyField($client, $field, $ierror))
Expand Down Expand Up @@ -128,7 +136,7 @@ public function checkSchema($fix = false, &$ierror = '')

break;
}

return;
$this->solrService->message('');
$this->solrService->message('Cleaning extra fields');
$currSchema = self::getCurrentSchema($client, $ierror);
Expand Down Expand Up @@ -297,7 +305,8 @@ private static function checkFieldNecessity(\Solarium\Client $client, $fields, $
*/
private static function checkFieldProperty(\Solarium\Client $client, $field, &$property, &$ierror)
{
$property = self::getFieldProperty($client, $field['type'], $field['data']['name'], $ierror);
$property = self::getFieldProperty($client, $field, $ierror);

if (! $property)
return false;

Expand Down Expand Up @@ -362,25 +371,27 @@ private static function getCurrentSchema(\Solarium\Client $client, &$ierror = ''
* @param string $fieldName
* @return boolean|mixed
*/
private static function getFieldProperty(\Solarium\Client $client, $fieldType, $fieldName, &$ierror = '')
private static function getFieldProperty(\Solarium\Client $client, $field, &$ierror = '')
{
$url = '';
if ($fieldType == 'field')
if ($field['type'] == 'field')
$url = 'schema/fields/';
if ($fieldType == 'dynamic-field')
if ($field['type'] == 'dynamic-field')
$url = 'schema/dynamicfields/';
if ($fieldType == 'field-type')
if ($field['type'] == 'field-type')
$url = 'schema/fieldtypes/';
if ($fieldType == 'copy-field')
$url = 'schema/copyfields/';
if ($field['type'] == 'copy-field')
return self::getCopyFieldProperty($client, $field, $ierror);

// $url = 'schema/copyfields/';
if ($url == '')
return false;

try {
$query = $client->createSelect();
$request = $client->createRequest($query);

$request->setHandler($url . $fieldName);
$request->setHandler($url . $field['data']['name']);

$response = $client->executeRequest($request);
if ($response->getStatusCode() != 200)
Expand Down Expand Up @@ -408,6 +419,41 @@ private static function getFieldProperty(\Solarium\Client $client, $fieldType, $
return false;
}

/**
* Get properties on a field based on its type and name
*
* @param \Solarium\Client $client
* @param string $fieldType
* @param string $fieldName
* @return boolean|mixed
*/
private static function getCopyFieldProperty(\Solarium\Client $client, $field, &$ierror = '')
{
$url = '';
if ($field['type'] != 'copy-field')
return false;

// $url = 'schema/copyfields/';

$curr = self::getCurrentSchema($client, $ierror);
if (! key_exists('copyFields', $curr['schema']))
return false;

$currCopyFields = $curr['schema']['copyFields'];

$app = new \OCA\Nextant\AppInfo\Application();
$app->getContainer()
->query('MiscService')
->log('___' . var_export($field, true) . '---' . var_export($currCopyFields, true));

foreach ($currCopyFields as $copyfield) {
if ($copyfield['dest'] === $field['data']['dest'])
return json_decode(json_encode($copyfield), true);
}

return false;
}

/**
* create field on the Solr Core
*
Expand Down Expand Up @@ -818,6 +864,52 @@ public static function solrSchema()
'name' => 'text_general',
'class' => 'solr.TextField',
'omitNorms' => false,
'indexAnalyzer' => array(
'tokenizer' => array(
'class' => 'solr.StandardTokenizerFactory'
),
'filters' => array(
array(
'class' => 'solr.StandardFilterFactory'
),
array(
'class' => 'solr.LowerCaseFilterFactory'
),
array(
'class' => 'solr.ASCIIFoldingFilterFactory'
),
array(
'class' => 'solr.NGramFilterFactory',
'maxGramSize' => '20',
'minGramSize' => '3'
)
)
),
'queryAnalyzer' => array(
'tokenizer' => array(
'class' => 'solr.StandardTokenizerFactory'
),
'filters' => array(
array(
'class' => 'solr.StandardFilterFactory'
),
array(
'class' => 'solr.LowerCaseFilterFactory'
),
array(
'class' => 'solr.ASCIIFoldingFilterFactory'
)
)
)
)
));

array_push($fields, array(
'type' => 'field-type',
'data' => array(
'name' => 'text_general_edge',
'class' => 'solr.TextField',
'omitNorms' => false,
'indexAnalyzer' => array(
'tokenizer' => array(
'class' => 'solr.StandardTokenizerFactory'
Expand All @@ -834,8 +926,7 @@ public static function solrSchema()
),
array(
'class' => 'solr.EdgeNGramFilterFactory',
// 'class' => 'solr.NGramFilterFactory',
'maxGramSize' => '15',
'maxGramSize' => '20',
'minGramSize' => '3'
)
)
Expand Down Expand Up @@ -896,6 +987,18 @@ public static function solrSchema()
)
));

// text
array_push($fields, array(
'type' => 'field',
'data' => array(
'name' => 'text_edge',
'type' => 'text_general_edge',
'indexed' => true,
'stored' => false,
'multiValued' => false
)
));

// text
array_push($fields, array(
'type' => 'field',
Expand Down Expand Up @@ -1069,6 +1172,19 @@ public static function solrSchema()
)
));

//
// copy-field
//

// copy-field
array_push($fields, array(
'type' => 'copy-field',
'data' => array(
'source' => 'text',
'dest' => 'text_edge'
)
));

return $fields;
}
}
Expand Down
4 changes: 3 additions & 1 deletion lib/Service/SolrService.php
Original file line number Diff line number Diff line change
Expand Up @@ -510,7 +510,9 @@ public function search($string, $options = array(), &$ierror = '')
if (substr($qstr, 0, 1) == '"')
$value = 150;

$q .= '(' . $oper . 'text:"' . $helper->escapeTerm(str_replace('"', '', $qstr)) . '"^' . $value . ') OR (' . $oper . 'text_light:"' . $helper->escapeTerm(str_replace('"', '', $qstr)) . '"^' . $value . ')';
$q .= '(' . $oper . 'text:"' . $helper->escapeTerm(str_replace('"', '', $qstr)) . '"^' . $value . ')';
$q .= ' OR (' . $oper . 'text_light:"' . $helper->escapeTerm(str_replace('"', '', $qstr)) . '"^' . $value . ')';
$q .= ' OR (' . $oper . 'text_edge:"' . $helper->escapeTerm(str_replace('"', '', $qstr)) . '"^' . ($value * 3) . ')';
}

if ($path !== '')
Expand Down

0 comments on commit 7db2f9f

Please sign in to comment.