mirror of
https://github.com/Hopiu/angular.js.git
synced 2026-03-16 23:30:23 +00:00
feat(ngdocs): Add FullText search to replace Google search in docs
This commit is contained in:
parent
0401a7f598
commit
3a49b7eec4
5 changed files with 2428 additions and 3 deletions
|
|
@ -0,0 +1,702 @@
|
|||
a
|
||||
able
|
||||
about
|
||||
above
|
||||
abst
|
||||
accordance
|
||||
according
|
||||
accordingly
|
||||
across
|
||||
act
|
||||
actually
|
||||
added
|
||||
adj
|
||||
adopted
|
||||
affected
|
||||
affecting
|
||||
affects
|
||||
after
|
||||
afterwards
|
||||
again
|
||||
against
|
||||
ah
|
||||
all
|
||||
almost
|
||||
alone
|
||||
along
|
||||
already
|
||||
also
|
||||
although
|
||||
always
|
||||
am
|
||||
among
|
||||
amongst
|
||||
an
|
||||
and
|
||||
announce
|
||||
another
|
||||
any
|
||||
anybody
|
||||
anyhow
|
||||
anymore
|
||||
anyone
|
||||
anything
|
||||
anyway
|
||||
anyways
|
||||
anywhere
|
||||
apparently
|
||||
approximately
|
||||
are
|
||||
aren
|
||||
arent
|
||||
arise
|
||||
around
|
||||
as
|
||||
aside
|
||||
ask
|
||||
asking
|
||||
at
|
||||
auth
|
||||
available
|
||||
away
|
||||
awfully
|
||||
b
|
||||
back
|
||||
be
|
||||
became
|
||||
because
|
||||
become
|
||||
becomes
|
||||
becoming
|
||||
been
|
||||
before
|
||||
beforehand
|
||||
begin
|
||||
beginning
|
||||
beginnings
|
||||
begins
|
||||
behind
|
||||
being
|
||||
believe
|
||||
below
|
||||
beside
|
||||
besides
|
||||
between
|
||||
beyond
|
||||
biol
|
||||
both
|
||||
brief
|
||||
briefly
|
||||
but
|
||||
by
|
||||
c
|
||||
ca
|
||||
came
|
||||
can
|
||||
cannot
|
||||
can't
|
||||
cant
|
||||
cause
|
||||
causes
|
||||
certain
|
||||
certainly
|
||||
co
|
||||
com
|
||||
come
|
||||
comes
|
||||
contain
|
||||
containing
|
||||
contains
|
||||
could
|
||||
couldnt
|
||||
d
|
||||
date
|
||||
did
|
||||
didn't
|
||||
didnt
|
||||
different
|
||||
do
|
||||
does
|
||||
doesn't
|
||||
doesnt
|
||||
doing
|
||||
done
|
||||
don't
|
||||
dont
|
||||
down
|
||||
downwards
|
||||
due
|
||||
during
|
||||
e
|
||||
each
|
||||
ed
|
||||
edu
|
||||
effect
|
||||
eg
|
||||
eight
|
||||
eighty
|
||||
either
|
||||
else
|
||||
elsewhere
|
||||
end
|
||||
ending
|
||||
enough
|
||||
especially
|
||||
et
|
||||
et-al
|
||||
etc
|
||||
even
|
||||
ever
|
||||
every
|
||||
everybody
|
||||
everyone
|
||||
everything
|
||||
everywhere
|
||||
ex
|
||||
except
|
||||
f
|
||||
far
|
||||
few
|
||||
ff
|
||||
fifth
|
||||
first
|
||||
five
|
||||
fix
|
||||
followed
|
||||
following
|
||||
follows
|
||||
for
|
||||
former
|
||||
formerly
|
||||
forth
|
||||
found
|
||||
four
|
||||
from
|
||||
further
|
||||
furthermore
|
||||
g
|
||||
gave
|
||||
get
|
||||
gets
|
||||
getting
|
||||
give
|
||||
given
|
||||
gives
|
||||
giving
|
||||
go
|
||||
goes
|
||||
gone
|
||||
got
|
||||
gotten
|
||||
h
|
||||
had
|
||||
happens
|
||||
hardly
|
||||
has
|
||||
hasn't
|
||||
hasnt
|
||||
have
|
||||
haven't
|
||||
havent
|
||||
having
|
||||
he
|
||||
hed
|
||||
hence
|
||||
her
|
||||
here
|
||||
hereafter
|
||||
hereby
|
||||
herein
|
||||
heres
|
||||
hereupon
|
||||
hers
|
||||
herself
|
||||
hes
|
||||
hi
|
||||
hid
|
||||
him
|
||||
himself
|
||||
his
|
||||
hither
|
||||
home
|
||||
how
|
||||
howbeit
|
||||
however
|
||||
hundred
|
||||
i
|
||||
id
|
||||
ie
|
||||
if
|
||||
i'll
|
||||
ill
|
||||
im
|
||||
immediate
|
||||
immediately
|
||||
importance
|
||||
important
|
||||
in
|
||||
inc
|
||||
indeed
|
||||
index
|
||||
information
|
||||
instead
|
||||
into
|
||||
invention
|
||||
inward
|
||||
is
|
||||
isn't
|
||||
isnt
|
||||
it
|
||||
itd
|
||||
it'll
|
||||
itll
|
||||
its
|
||||
itself
|
||||
i've
|
||||
ive
|
||||
j
|
||||
just
|
||||
k
|
||||
keep
|
||||
keeps
|
||||
kept
|
||||
keys
|
||||
kg
|
||||
km
|
||||
know
|
||||
known
|
||||
knows
|
||||
l
|
||||
largely
|
||||
last
|
||||
lately
|
||||
later
|
||||
latter
|
||||
latterly
|
||||
least
|
||||
less
|
||||
lest
|
||||
let
|
||||
lets
|
||||
like
|
||||
liked
|
||||
likely
|
||||
line
|
||||
little
|
||||
'll
|
||||
'll
|
||||
look
|
||||
looking
|
||||
looks
|
||||
ltd
|
||||
m
|
||||
made
|
||||
mainly
|
||||
make
|
||||
makes
|
||||
many
|
||||
may
|
||||
maybe
|
||||
me
|
||||
mean
|
||||
means
|
||||
meantime
|
||||
meanwhile
|
||||
merely
|
||||
mg
|
||||
might
|
||||
million
|
||||
miss
|
||||
ml
|
||||
more
|
||||
moreover
|
||||
most
|
||||
mostly
|
||||
mr
|
||||
mrs
|
||||
much
|
||||
mug
|
||||
must
|
||||
my
|
||||
myself
|
||||
n
|
||||
na
|
||||
name
|
||||
namely
|
||||
nay
|
||||
nd
|
||||
near
|
||||
nearly
|
||||
necessarily
|
||||
necessary
|
||||
need
|
||||
needs
|
||||
neither
|
||||
never
|
||||
nevertheless
|
||||
new
|
||||
next
|
||||
nine
|
||||
ninety
|
||||
no
|
||||
nobody
|
||||
non
|
||||
none
|
||||
nonetheless
|
||||
noone
|
||||
nor
|
||||
normally
|
||||
nos
|
||||
not
|
||||
noted
|
||||
nothing
|
||||
now
|
||||
nowhere
|
||||
o
|
||||
obtain
|
||||
obtained
|
||||
obviously
|
||||
of
|
||||
off
|
||||
often
|
||||
oh
|
||||
ok
|
||||
okay
|
||||
old
|
||||
omitted
|
||||
on
|
||||
once
|
||||
one
|
||||
ones
|
||||
only
|
||||
onto
|
||||
or
|
||||
ord
|
||||
other
|
||||
others
|
||||
otherwise
|
||||
ought
|
||||
our
|
||||
ours
|
||||
ourselves
|
||||
out
|
||||
outside
|
||||
over
|
||||
overall
|
||||
owing
|
||||
own
|
||||
p
|
||||
page
|
||||
pages
|
||||
part
|
||||
particular
|
||||
particularly
|
||||
past
|
||||
per
|
||||
perhaps
|
||||
placed
|
||||
please
|
||||
plus
|
||||
poorly
|
||||
possible
|
||||
possibly
|
||||
potentially
|
||||
pp
|
||||
predominantly
|
||||
present
|
||||
previously
|
||||
primarily
|
||||
probably
|
||||
promptly
|
||||
proud
|
||||
provides
|
||||
put
|
||||
q
|
||||
que
|
||||
quickly
|
||||
quite
|
||||
qv
|
||||
r
|
||||
ran
|
||||
rather
|
||||
rd
|
||||
re
|
||||
readily
|
||||
really
|
||||
recent
|
||||
recently
|
||||
ref
|
||||
refs
|
||||
regarding
|
||||
regardless
|
||||
regards
|
||||
related
|
||||
relatively
|
||||
research
|
||||
respectively
|
||||
resulted
|
||||
resulting
|
||||
results
|
||||
right
|
||||
run
|
||||
s
|
||||
said
|
||||
same
|
||||
saw
|
||||
say
|
||||
saying
|
||||
says
|
||||
sec
|
||||
section
|
||||
see
|
||||
seeing
|
||||
seem
|
||||
seemed
|
||||
seeming
|
||||
seems
|
||||
seen
|
||||
self
|
||||
selves
|
||||
sent
|
||||
seven
|
||||
several
|
||||
shall
|
||||
she
|
||||
shed
|
||||
she'll
|
||||
shell
|
||||
shes
|
||||
should
|
||||
shouldn't
|
||||
shouldnt
|
||||
show
|
||||
showed
|
||||
shown
|
||||
showns
|
||||
shows
|
||||
significant
|
||||
significantly
|
||||
similar
|
||||
similarly
|
||||
since
|
||||
six
|
||||
slightly
|
||||
so
|
||||
some
|
||||
somebody
|
||||
somehow
|
||||
someone
|
||||
somethan
|
||||
something
|
||||
sometime
|
||||
sometimes
|
||||
somewhat
|
||||
somewhere
|
||||
soon
|
||||
sorry
|
||||
specifically
|
||||
specified
|
||||
specify
|
||||
specifying
|
||||
state
|
||||
states
|
||||
still
|
||||
stop
|
||||
strongly
|
||||
sub
|
||||
substantially
|
||||
successfully
|
||||
such
|
||||
sufficiently
|
||||
suggest
|
||||
sup
|
||||
sure
|
||||
t
|
||||
take
|
||||
taken
|
||||
taking
|
||||
tell
|
||||
tends
|
||||
th
|
||||
than
|
||||
thank
|
||||
thanks
|
||||
thanx
|
||||
that
|
||||
that'll
|
||||
thatll
|
||||
thats
|
||||
that've
|
||||
thatve
|
||||
the
|
||||
their
|
||||
theirs
|
||||
them
|
||||
themselves
|
||||
then
|
||||
thence
|
||||
there
|
||||
thereafter
|
||||
thereby
|
||||
thered
|
||||
therefore
|
||||
therein
|
||||
there'll
|
||||
therell
|
||||
thereof
|
||||
therere
|
||||
theres
|
||||
thereto
|
||||
thereupon
|
||||
there've
|
||||
thereve
|
||||
these
|
||||
they
|
||||
theyd
|
||||
they'll
|
||||
theyll
|
||||
theyre
|
||||
they've
|
||||
theyve
|
||||
think
|
||||
this
|
||||
those
|
||||
thou
|
||||
though
|
||||
thoughh
|
||||
thousand
|
||||
throug
|
||||
through
|
||||
throughout
|
||||
thru
|
||||
thus
|
||||
til
|
||||
tip
|
||||
to
|
||||
together
|
||||
too
|
||||
took
|
||||
toward
|
||||
towards
|
||||
tried
|
||||
tries
|
||||
truly
|
||||
try
|
||||
trying
|
||||
ts
|
||||
twice
|
||||
two
|
||||
u
|
||||
un
|
||||
under
|
||||
unfortunately
|
||||
unless
|
||||
unlike
|
||||
unlikely
|
||||
until
|
||||
unto
|
||||
up
|
||||
upon
|
||||
ups
|
||||
us
|
||||
use
|
||||
used
|
||||
useful
|
||||
usefully
|
||||
usefulness
|
||||
uses
|
||||
using
|
||||
usually
|
||||
v
|
||||
value
|
||||
various
|
||||
've
|
||||
've
|
||||
very
|
||||
via
|
||||
viz
|
||||
vol
|
||||
vols
|
||||
vs
|
||||
w
|
||||
want
|
||||
wants
|
||||
was
|
||||
wasn't
|
||||
wasnt
|
||||
way
|
||||
we
|
||||
wed
|
||||
welcome
|
||||
we'll
|
||||
well
|
||||
went
|
||||
were
|
||||
weren't
|
||||
werent
|
||||
we've
|
||||
weve
|
||||
what
|
||||
whatever
|
||||
what'll
|
||||
whatll
|
||||
whats
|
||||
when
|
||||
whence
|
||||
whenever
|
||||
where
|
||||
whereafter
|
||||
whereas
|
||||
whereby
|
||||
wherein
|
||||
wheres
|
||||
whereupon
|
||||
wherever
|
||||
whether
|
||||
which
|
||||
while
|
||||
whim
|
||||
whither
|
||||
who
|
||||
whod
|
||||
whoever
|
||||
whole
|
||||
who'll
|
||||
wholl
|
||||
whom
|
||||
whomever
|
||||
whos
|
||||
whose
|
||||
why
|
||||
widely
|
||||
will
|
||||
willing
|
||||
wish
|
||||
with
|
||||
within
|
||||
without
|
||||
won't
|
||||
wont
|
||||
words
|
||||
world
|
||||
would
|
||||
wouldn't
|
||||
wouldnt
|
||||
www
|
||||
x
|
||||
y
|
||||
yes
|
||||
yet
|
||||
you
|
||||
youd
|
||||
you'll
|
||||
youll
|
||||
your
|
||||
youre
|
||||
yours
|
||||
yourself
|
||||
yourselves
|
||||
you've
|
||||
youve
|
||||
z
|
||||
zero
|
||||
|
|
@ -259,4 +259,39 @@ ul.events > li > h3 {
|
|||
.syntax-links + pre {
|
||||
border-top-left-radius:0;
|
||||
border-top-right-radius:0;
|
||||
|
||||
.search-results {
|
||||
clear:both;
|
||||
display:table;
|
||||
width:100%;
|
||||
}
|
||||
|
||||
.search-results > .search-group {
|
||||
vertical-align:top;
|
||||
padding:10px 0;
|
||||
display:table-cell;
|
||||
}
|
||||
|
||||
.search-group.cols-1 { width:100%; }
|
||||
.search-group.cols-2 { width:50%; }
|
||||
.search-group.cols-3 { width:33%; }
|
||||
.search-group.cols-4 { width:25%; }
|
||||
|
||||
.search-close {
|
||||
z-index:1029;
|
||||
position:absolute;
|
||||
bottom:-25px;
|
||||
left:80%;
|
||||
text-align:center;
|
||||
line-height:50px;
|
||||
width:50px;
|
||||
font-size:2em;
|
||||
background:#222222;
|
||||
border-radius:15px;
|
||||
}
|
||||
|
||||
.search-close span {
|
||||
text-decoration:none;
|
||||
position:relative;
|
||||
z-index:1031;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -43,6 +43,7 @@
|
|||
addTag('script', {src: path('angular-mobile.js') }, sync);
|
||||
addTag('script', {src: path('angular-bootstrap.js') }, sync);
|
||||
addTag('script', {src: path('angular-bootstrap-prettify.js') }, sync);
|
||||
addTag('script', {src: 'js/lunr.js' }, sync);
|
||||
addTag('script', {src: 'js/docs.js'}, sync);
|
||||
addTag('script', {src: 'docs-keywords.js'}, sync);
|
||||
|
||||
|
|
@ -112,7 +113,7 @@
|
|||
</head>
|
||||
|
||||
<body>
|
||||
<header class="header">
|
||||
<header class="header" ng-controller="DocsNavigationCtrl">
|
||||
<div class="navbar navbar-fixed-top">
|
||||
<div class="navbar-inner">
|
||||
<div class="container">
|
||||
|
|
@ -166,10 +167,21 @@
|
|||
</li>
|
||||
<li class="divider-vertical"></li>
|
||||
</ul>
|
||||
<form class="navbar-search pull-right" method="GET" action="https://www.google.com/search">
|
||||
<input type="text" name="as_q" class="search-query" placeholder="Search">
|
||||
<form class="navbar-search pull-right" ng-submit="submit()">
|
||||
<input type="text" name="as_q" class="search-query" placeholder="Search" ng-change="search(q)" ng-model="q" autocomplete="off">
|
||||
<input type="hidden" name="as_sitesearch" value="angularjs.org">
|
||||
</form>
|
||||
<div ng-show="hasResults" class="search-results">
|
||||
<a href="" ng-click="hideResults()" class="search-close">
|
||||
<span class="icon-remove-sign"></span>
|
||||
</a>
|
||||
<div ng-repeat="(key, value) in results" class="search-group" ng-class="colClassName">
|
||||
<h4>{{ key }}</h4>
|
||||
<div ng-repeat="item in value" class="search-result">
|
||||
<a ng-click="hideResults()" href="{{ item.url }}">{{ item.shortName }}</a>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
|
|
|||
|
|
@ -4,6 +4,122 @@ var docsApp = {
|
|||
serviceFactory: {}
|
||||
};
|
||||
|
||||
docsApp.controller.DocsNavigationCtrl = ['$scope', 'fullTextSearch', '$location', function($scope, fullTextSearch, $location) {
|
||||
fullTextSearch.init();
|
||||
$scope.search = function(q) {
|
||||
fullTextSearch.search(q, function(results) {
|
||||
if(q && q.length >= 4) {
|
||||
$scope.results = results;
|
||||
var totalSections = 0;
|
||||
for(var i in results) {
|
||||
++totalSections;
|
||||
}
|
||||
if(totalSections > 0) {
|
||||
$scope.colClassName = 'cols-' + totalSections;
|
||||
$scope.hasResults = true;
|
||||
}
|
||||
else {
|
||||
$scope.hasResults = false;
|
||||
}
|
||||
}
|
||||
else {
|
||||
$scope.hasResults = false;
|
||||
}
|
||||
if(!$scope.$$phase) $scope.$apply();
|
||||
});
|
||||
};
|
||||
$scope.submit = function() {
|
||||
var result;
|
||||
for(var i in $scope.results) {
|
||||
result = $scope.results[i][0];
|
||||
if(result) {
|
||||
break;
|
||||
}
|
||||
}
|
||||
if(result) {
|
||||
$location.path(result.url);
|
||||
$scope.hideResults();
|
||||
}
|
||||
};
|
||||
$scope.hideResults = function() {
|
||||
$scope.hasResults = false;
|
||||
$scope.q = '';
|
||||
};
|
||||
}];
|
||||
|
||||
docsApp.serviceFactory.fullTextSearch = ['$q', '$rootScope', function($q, $rootScope) {
|
||||
return {
|
||||
dbName : 'docs',
|
||||
indexName : 'docsindex',
|
||||
|
||||
init : function(onReady) {
|
||||
this.init = function() {};
|
||||
|
||||
var self = this;
|
||||
this.deferReady = $q.defer();
|
||||
this.readyPromise = this.deferReady.promise;
|
||||
|
||||
this.engine = lunr(function () {
|
||||
this.ref('id');
|
||||
this.field('title', {boost: 50});
|
||||
this.field('description', { boost : 20 });
|
||||
});
|
||||
this.prepare();
|
||||
this.onReady();
|
||||
},
|
||||
onReady : function() {
|
||||
this.ready = true;
|
||||
var self = this;
|
||||
self.deferReady.resolve();
|
||||
if(!$rootScope.$$phase) {
|
||||
$rootScope.$apply();
|
||||
}
|
||||
},
|
||||
whenReady : function(fn) {
|
||||
if(this.ready) {
|
||||
fn();
|
||||
}
|
||||
else {
|
||||
this.init();
|
||||
this.readyPromise.then(fn);
|
||||
}
|
||||
},
|
||||
prepare : function(injector, callback) {
|
||||
for(var i=0;i<NG_PAGES.length;i++) {
|
||||
var page = NG_PAGES[i];
|
||||
var title = page.shortName;
|
||||
if(title.charAt(0) == 'n' && title.charAt(1) == 'g') {
|
||||
title = title + ' ' + title.substr(2);
|
||||
}
|
||||
this.engine.add({
|
||||
id: i,
|
||||
title: title,
|
||||
description: page.keywords
|
||||
});
|
||||
}
|
||||
},
|
||||
search : function(q, onReady) {
|
||||
var self = this;
|
||||
this.whenReady(function() {
|
||||
var data = [];
|
||||
var results = self.engine.search(q);
|
||||
var groups = {};
|
||||
angular.forEach(results, function(result) {
|
||||
var item = NG_PAGES[result.ref];
|
||||
var section = item.section;
|
||||
if(section == 'cookbook') {
|
||||
section = 'tutorial';
|
||||
}
|
||||
groups[section] = groups[section] || [];
|
||||
if(groups[section].length < 15) {
|
||||
groups[section].push(item);
|
||||
}
|
||||
})
|
||||
onReady(groups);
|
||||
})
|
||||
}
|
||||
};
|
||||
}];
|
||||
|
||||
docsApp.directive.focused = function($timeout) {
|
||||
return function(scope, element, attrs) {
|
||||
|
|
|
|||
1560
docs/src/templates/js/lunr.js
Normal file
1560
docs/src/templates/js/lunr.js
Normal file
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue