Skip to content

Commit

Permalink
Item12497:
Browse files Browse the repository at this point in the history
   * improved rest endpoint to cope with different infos in groups in a cleaner way
   * added paging for groups
   * added caching for autocompletions
   * improved templating of list items



git-svn-id: http://svn.foswiki.org/trunk/SolrPlugin@16737 0b4bb1d4-4e5a-0410-9cc4-b2b747904278
  • Loading branch information
MichaelDaum authored and MichaelDaum committed May 16, 2013
1 parent 88462c5 commit 7af7f1b
Show file tree
Hide file tree
Showing 7 changed files with 197 additions and 88 deletions.
2 changes: 1 addition & 1 deletion data/System/SolrAjaxWikiUsersViewTemplate.txt
Expand Up @@ -58,7 +58,7 @@
<div class='solrSearchHit solrTopicHit foswikiProfileInfo'>
{{tmpl($data, $item) solrHitTemplate_userimage}}
<h4><a href='${url}'>${title}</a></h4>
<ul class='foswikiTopicInfo jqShrinkUrls {size:15}'>
<ul class='foswikiTopicInfo jqShrinkUrls' data-size='15'>
{{if field_Profession_s}}<li>%MAKETEXT{"Profession"}%: ${field_Profession_s}</li>{{/if}}
{{if field_Telephone_s}}<li>%MAKETEXT{"Tel"}%: ${field_Telephone_s}</li>{{/if}}
{{if field_Email_s}}<li>%MAKETEXT{"Email"}%: <a mailto='${field_Email_s}'>${field_Email_s}</a></li>{{/if}}
Expand Down
2 changes: 1 addition & 1 deletion data/System/SolrWikiUsersViewTemplate.txt
Expand Up @@ -70,7 +70,7 @@
%TMPL:DEF{"solr::hits::list"}%%SOLRFORMAT{"solr1"
header="<div class='solrSearchHits solrSearchHitsList jqPrettyPhoto {itemSelector:\".solrImageFrame a\"}'>"
footer="%CLEAR%</div>"
format="<div class='solrSearchHit foswikiProfileInfo jqShrinkUrls {size:15}'>
format="<div class='solrSearchHit foswikiProfileInfo jqShrinkUrls' data-size='15'>
$percntTMPL:P{\"solr::hits::userimage\" web=\"$web\" topic=\"$topic\"}$percnt<!-- -->
<h4>[[$web.$topic]] ($percntUSERINFO{\"$topic\" format=\"$username\"}$percnt)</h4>
<ul class='foswikiTopicInfo'>
Expand Down
1 change: 1 addition & 0 deletions lib/Foswiki/Plugins/SolrPlugin/DEPENDENCIES
Expand Up @@ -15,3 +15,4 @@ Moose,>=0.63,cpan,Required.
XML::Easy,>0,cpan,Required.
HTML::Entities,>=3.64,cpan,Required.
Digest::SHA1,>0.0,cpan,Required.
File::MMagic,>0,cpan,Required.
2 changes: 1 addition & 1 deletion lib/Foswiki/Plugins/SolrPlugin/Index.pm
@@ -1,6 +1,6 @@
# Plugin for Foswiki - The Free and Open Source Wiki, http://foswiki.org/
#
# Copyright (C) 2009-2011 Michael Daum http://michaeldaumconsulting.com
# Copyright (C) 2009-2013 Michael Daum http://michaeldaumconsulting.com
#
# This program is free software; you can redistribute it and/or
# modify it under the terms of the GNU General Public License
Expand Down
92 changes: 65 additions & 27 deletions lib/Foswiki/Plugins/SolrPlugin/Search.pm
Expand Up @@ -676,8 +676,28 @@ sub restSOLRAUTOSUGGEST {
my $theLimit = $query->param('limit');
$theLimit = 5 unless defined $theLimit;

my $theOffset = $query->param('offset');
$theOffset = 0 unless defined $theOffset;

my $theFields = $query->param('fields');
$theFields = "name,web,topic,container_title,title,thumbnail,url,score,type" unless defined $theFields;
$theFields = "name,web,topic,container_title,title,thumbnail,url,score,type,field_Telephone_s,field_Phone_s,field_Mobile_s" unless defined $theFields;

my $theGroups = $query->param('groups');
$theGroups = 'persons, topics, attachments' unless defined $theGroups;

my $userForm = $Foswiki::cfg{SolrPlugin}{PersonDataForm} || $Foswiki::cfg{PersonDataForm} || $Foswiki::cfg{Ldap}{PersonDataForm} || '*UserForm';
my %filter = (
persons => "form:$userForm",
topics => "-form:$userForm type:topic",
attachments => "-type:topic",
);

my @groupQuery = ();
foreach my $group (split(/\s*,\s*/, $theGroups)) {
my $filter = $filter{$group};
next unless defined $filter;
push @groupQuery, $filter;
}

my $wikiUser = Foswiki::Func::getWikiName();

Expand All @@ -688,25 +708,16 @@ sub restSOLRAUTOSUGGEST {
push(@filter, "(access_granted:$wikiUser OR access_granted:all)")
unless Foswiki::Func::isAnAdmin($wikiUser);

my $userForm = $Foswiki::cfg{PersonDataForm} || $Foswiki::cfg{Ldap}{PersonDataForm} || 'UserForm';

my $personTopicFilter = "form:*$userForm";
my $topicFilter = "-form:*$userForm type:topic";
my $attachmentFilter = "-type:topic";

my %params = (
q => $theQuery,
qt => "edismax",
indent => "true",
group => "true",
fl => $theFields,
"group.sort" => "score desc",
"group.offset" => $theOffset,
"group.limit" => $theLimit,
"group.query" => [
$personTopicFilter,
$topicFilter,
$attachmentFilter,
],
"group.query" => \@groupQuery,
fq => \@filter,
);

Expand Down Expand Up @@ -734,32 +745,54 @@ sub restSOLRAUTOSUGGEST {

if ($status == 200 && !$theRaw) {
my @autoSuggestions = ();
my $group;

# person topics
if (defined $result->{grouped}{$personTopicFilter}) {
foreach my $doc (@{$result->{grouped}{$personTopicFilter}{doclist}{docs}}) {
$group = $result->{grouped}{$filter{persons}};
if (defined $group) {
my @docs = ();
foreach my $doc (@{$group->{doclist}{docs}}) {
my $phoneNumber = $doc->{field_Telephone_s} || $doc->{field_Phone_s} || $doc->{field_Mobile_s};
$doc->{phoneNumber} = $phoneNumber if defined $phoneNumber;

$doc->{thumbnail} = $Foswiki::cfg{PubUrlPath}."/".$Foswiki::cfg{SystemWebName}."/JQueryPlugin/images/nobody.gif"
unless defined $doc->{thumbnail};
$doc->{_section} = 'persons';
$doc->{value} = $doc->{title}; # TODO
push @autoSuggestions, $doc;

$doc->{value} = $doc->{title};

push @docs, $doc;
}
push @autoSuggestions, {
"group" => "persons",
"start" => $group->{doclist}{start},
"numFound" => $group->{doclist}{numFound},
"docs" => \@docs
} if @docs;
}

# normal topics
if (defined $result->{grouped}{$topicFilter}) {
foreach my $doc (@{$result->{grouped}{$topicFilter}{doclist}{docs}}) {
$group = $result->{grouped}{$filter{topics}};
if (defined $group) {
my @docs = ();
foreach my $doc (@{$group->{doclist}{docs}}) {
$doc->{thumbnail} = $this->mapToIconFileName("unknown", 48)
unless defined $doc->{thumbnail};
$doc->{_section} = 'topics';
$doc->{value} = $doc->{title}; # TODO
push @autoSuggestions, $doc;
$doc->{value} = $doc->{title};
push @docs, $doc;
}
push @autoSuggestions, {
"group" => "topics",
"start" => $group->{doclist}{start},
"numFound" => $group->{doclist}{numFound},
"docs" => \@docs
} if @docs;
}

# attachments
if (defined $result->{grouped}{$attachmentFilter}) {
foreach my $doc (@{$result->{grouped}{$attachmentFilter}{doclist}{docs}}) {
$group = $result->{grouped}{$filter{attachments}};
if (defined $group) {
my @docs = ();
foreach my $doc (@{$group->{doclist}{docs}}) {
unless (defined $doc->{thumbnail}) {
if ($doc->{type} =~ /^(gif|jpe?g|png|bmp|svg)$/i) {
$doc->{thumbnail} = $doc->{name};
Expand All @@ -769,10 +802,15 @@ sub restSOLRAUTOSUGGEST {
$doc->{thumbnail} = $this->mapToIconFileName($ext, 48);
}
}
$doc->{_section} = 'attachments';
$doc->{value} = $doc->{title}; # TODO
push @autoSuggestions, $doc;
$doc->{value} = $doc->{title};
push @docs, $doc;
}
push @autoSuggestions, {
"group" => "attachments",
"start" => $group->{doclist}{start},
"numFound" => $group->{doclist}{numFound},
"docs" => \@docs
} if @docs;
}

$result = JSON::to_json(\@autoSuggestions, {utf8=>1, pretty=>1});
Expand Down
27 changes: 20 additions & 7 deletions pub/System/SolrPlugin/jquery.autosuggest.uncompressed.css
Expand Up @@ -25,20 +25,33 @@
overflow:hidden;
}
.ui-autosuggest .ui-menu-item.ui-widget-header {
padding:5px;
border-top:1px solid #ddd;
font-weight:bold;
padding:0.2em 0.5em;
}

.ui-autosuggest .ui-widget-header .ui-autosuggest-more {
.ui-autosuggest .ui-widget-header .ui-autosuggest-pager {
float:right;
font-weight:normal;
margin-right:15px;
position:relative;
margin:0.2em 0.5em;
width:45px;
height:10px;
}
.ui-autosuggest .ui-widget-header .ui-autosuggest-pager a {
display:inline-block;
width:16px;
height:16px;
overflow:hidden;
margin:0;
padding:0;
color:#7B7E81;
position:initial;
}
.ui-autosuggest .ui-widget-header a.ui-autosuggest-prev {
margin-right:5px;
visibility:hidden;
}
.ui-autosuggest .ui-widget-header .ui-autosuggest-more:hover {
text-decoration:underline;
.ui-autosuggest .ui-widget-header .ui-autosuggest-pager a:hover {
text-decoration:none;
background-color:transparent;
}
.ui-autosuggest .ui-menu-item .thumbnail.dummy {
Expand Down

0 comments on commit 7af7f1b

Please sign in to comment.