Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: Elevation Configuration #56

Open
wants to merge 2 commits into
base: primary
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions Solr/5/extras/elevate.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,14 +23,14 @@

<elevate>
<query text="foo bar">
<doc id="1"/>
<doc id="2"/>
<doc id="3"/>
<doc id="Page-1"/>
<doc id="Page-2"/>
<doc id="Page-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 -->
<doc id="Page-3"/> <!-- put Page with ID = 3 at the top -->
<doc id="Page-2" exclude="true"/> <!-- exclude Page ID 2 -->
</query>

</elevate>
16 changes: 8 additions & 8 deletions Solr/5/extras/solrconfig.xml
Original file line number Diff line number Diff line change
Expand Up @@ -810,7 +810,7 @@
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">_text</str>
<str name="df">text</str>
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The rename is good, but I'm mildly afraid it might clash at some point with the Text DBObject from SilverStripe, causing confusion in naming etc.. Do you have any thoughts about that?

</lst>
<!-- In addition to defaults, "appends" params can be specified
to identify values which should be appended to the list of
Expand Down Expand Up @@ -889,7 +889,7 @@
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">_text</str>
<str name="df">text</str>
</lst>
</requestHandler>

Expand Down Expand Up @@ -931,7 +931,7 @@
text^0.5 features^1.0 name^1.2 sku^1.5 id^10.0 manu^1.1 cat^1.4
title^10.0 description^5.0 keywords^5.0 author^2.0 resourcename^1.0
</str>
<str name="df">_text</str>
<str name="df">text</str>
<str name="mm">100%</str>
<str name="q.alt">*:*</str>
<str name="rows">10</str>
Expand Down Expand Up @@ -1271,7 +1271,7 @@
<!-- a spellchecker built from a field of the main index -->
<lst name="spellchecker">
<str name="name">default</str>
<str name="field">_text</str>
<str name="field">text</str>
<str name="classname">solr.DirectSolrSpellChecker</str>
<!-- the spellcheck distance measure used, the default is the internal levenshtein -->
<str name="distanceMeasure">internal</str>
Expand Down Expand Up @@ -1320,7 +1320,7 @@
<lst name="spellchecker">
<str name="name">wordbreak</str>
<str name="classname">solr.WordBreakSolrSpellChecker</str>
<str name="field">_text</str>
<str name="field">text</str>
<str name="combineWords">true</str>
<str name="breakWords">true</str>
<int name="maxChanges">10</int>
Expand Down Expand Up @@ -1380,7 +1380,7 @@
-->
<requestHandler name="/spell" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">_text</str>
<str name="df">text</str>
<!-- Solr will use suggestions from both the 'default' spellchecker
and from the 'wordbreak' spellchecker and combine them.
collations (re-written queries) can include a combination of
Expand Down Expand Up @@ -1417,7 +1417,7 @@
-->
<requestHandler name="/tvrh" class="solr.SearchHandler" startup="lazy">
<lst name="defaults">
<str name="df">_text</str>
<str name="df">text</str>
<bool name="tv">true</bool>
</lst>
<arr name="last-components">
Expand Down Expand Up @@ -1564,7 +1564,7 @@
-->
<searchComponent name="elevator" class="solr.QueryElevationComponent">
<!-- pick a fieldType to analyze queries -->
<str name="queryFieldType">string</str>
<str name="queryFieldType">text</str>
<str name="config-file">elevate.xml</str>
</searchComponent>

Expand Down
26 changes: 26 additions & 0 deletions src/Admins/SearchAdmin.php
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,11 @@
use Firesphere\SolrSearch\Models\SolrLog;
use SilverStripe\Admin\ModelAdmin;
use SilverStripe\View\Requirements;
use Firesphere\SolrSearch\Forms\GridFieldOrderableSearch;
use Firesphere\SolrSearch\Models\SearchClass;
use Firesphere\SolrSearch\Models\Elevation;
use Firesphere\SolrSearch\Models\ElevatedItem;
use Symbiote\GridFieldExtensions\GridFieldOrderableRows;

/**
* Class \Firesphere\SolrSearch\Admins\SearchAdmin
Expand All @@ -31,6 +36,8 @@ class SearchAdmin extends ModelAdmin
SearchSynonym::class,
SolrLog::class,
DirtyClass::class,
Elevation::class,
ElevatedItem::class,
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't ElevatedItem be managed through Elevation?

];

/**
Expand All @@ -57,4 +64,23 @@ public function init()

Requirements::css('firesphere/solr-search:client/dist/main.css');
}

public function getEditForm($id = null, $fields = null)
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid variables with short names like $id. Configured minimum length is 3.

{
$oldImportFrom = $this->showImportForm;
$this->showImportForm = false;
/** @var GridField $gridField */
$form = parent::getEditForm($id, $fields);
$this->showImportForm = $oldImportFrom;

if ($this->modelClass === ElevatedItem::class) {
$gridField = $form->Fields()->dataFieldByName($this->sanitiseClassName($this->modelClass));

$gridField
->getConfig()
->addComponent(new GridFieldOrderableRows('Rank'));
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Maybe also add inline editing if it's possible? Saves users from clicking "new" etc.

}

return $form;
}
}
26 changes: 26 additions & 0 deletions src/Models/ElevatedItem.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
<?php

namespace Firesphere\SolrSearch\Models;

use SilverStripe\ORM\DataObject;

class ElevatedItem extends DataObject
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $table_name is not named in camelCase.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $belongs_many_many is not named in camelCase.

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The property $summary_fields is not named in camelCase.

{
private static $table_name = 'ElevatedItem';
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Avoid unused private fields such as '$table_name'.


private static $db = [
'Rank' => 'Int',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you stick to my standard of aligning the =>? Sorry, I'm really picky 😄

'Title' => 'Varchar(255)',
'ObjectClass' => 'Varchar(255)',
'ObjectID' => 'Int',
'SolrID' => 'Varchar(255)',
'Include' => 'Boolean(1)',
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For readability, I prefer using Boolean(true) and Boolean(false) over 1 and 0

'Exclude' => 'Boolean(0)',
];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Very thorough $db settings. I like!


private static $belongs_many_many = [
'Keywords' => Elevation::class,
];

private static $summary_fields = ['Title', 'Rank', 'ObjectClass', 'SolrID', 'Include', 'Exclude'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please make it a list 😄

Also, I think ObjectClass should be replaced with a method, that returns the Singular name of the class. A bit more friendly :)

}
20 changes: 20 additions & 0 deletions src/Models/Elevation.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<?php

namespace Firesphere\SolrSearch\Models;

use SilverStripe\ORM\DataObject;

class Elevation extends DataObject
{
private static $table_name = 'Elevation';

private static $db = [
'Keyword' => 'Varchar(255)',
];

private static $many_many = [
'Items' => ElevatedItem::class,
];

private static $summary_fields = ['ID', 'Keyword'];
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As above, it would be good to list them out instead of using as a string.

Also, I'd add Items.Count, so people can see how many items are elevated by this keyword without having to look deeper.

}