TA的每日心情 | 开心 2019-8-21 08:44 |
---|
签到天数: 163 天 [LV.7]常住居民III
|
发表于 2021-10-31 11:10:51
|
显示全部楼层
. q5 n4 d) S/ I4 ]加了一个纯 js 版,无需node环境。只需两个文件(index.html 和 app.js, 其实可以整成一个文件)。参看https://github.com/ffreemt/meilisearch-plaintext读我文件的最后一条。# }. n7 W U# V" I% _
9 d- I; W% J- M. c, [
index.html
+ p8 d1 I) I% m m Q# |- <!DOCTYPE html>
/ O& `5 K- U' B4 i! ]/ @0 g! e - <html lang="en">% c* r* g3 `8 ?) C# T5 v- R
- <head>3 F6 O. I6 K# c) |. O8 w0 P+ n
- <meta charset="utf-8" />2 o0 R* A2 `; Z5 W
- </head>
' W; z+ N |! Z; U) x" H! ]
! I* P, f3 ]! y/ a& Y- <body>* F8 @" q+ `4 N. k
- <div>
/ G' I; [5 \# ? Y, v+ U - <div id="searchbox"></div>& M( q5 s9 y! f( b9 B
- <div id="hits"></div>
+ ?5 }* k7 S3 A" w0 A q: H - </div>
& H/ g. y& K$ k; E/ H - 8 T+ a5 K$ A5 ~& O5 H3 M2 X
- <script src="https://cdn.jsdelivr.net/npm/@meilisearch/instant-meilisearch/dist/instant-meilisearch.umd.min.js"></script>
; }% H" S/ H. H# O - <script src="https://cdn.jsdelivr.net/npm/instantsearch.js@4"></script>, C+ u" S4 j8 r! n
- <script src="./app.js"></script>. c( @. F' p3 r! N1 a
- </body>; @) V0 j0 x: S- f( ?8 j7 Y9 R1 z' d
- </html>
复制代码 ( m: ]* g1 Y. I' q2 g* }5 h
& i9 |7 q% c7 M; T1 M
app.js; m. @/ s$ ~$ p* s
- const search = instantsearch({4 t7 [' x% c8 c1 Z6 n: t; L6 U
- // indexName: 'steam-video-games',3 m( h* l1 _. w" q5 F
- indexName: 'movies',0 _6 n# y) q. w% d" Q; S9 e# s
- searchClient: instantMeiliSearch(( Q2 o' a; K# G& B: S8 _" \, k
- // 'https://demos.meilisearch.com',$ B- G5 L+ \/ s2 x, N" \0 n+ J8 c
- 'http://acone3:7700',
0 T6 r) L" D" a1 K5 Z6 n. E8 d - 'dc3fedaf922de8937fdea01f0a7d59557f1fd31832cb8440ce94231cfdde7f25'( K- @' y, g' D& p5 |' N- G
- ),
- t7 }" I, ~+ D; ]; [7 q - })( O' I0 v' r9 e+ f; d/ S. x
- % Q' r! Z5 e, H1 A& M
- search.addWidgets([$ H) V2 `: q* ] r- l" {
- instantsearch.widgets.searchBox({
& u q: L. J( K5 X7 k - container: '#searchbox',
9 Z. N; b: M2 r9 h$ a - }),
2 x+ Y7 J0 e k% Q$ w3 y - instantsearch.widgets.hits({
! P; z$ s+ o7 Q2 q8 ^ M - container: '#hits',
+ R- d+ w- @& s, A - templates: {
) L# x# j. I) _# Z8 M* ^- ~' G - item: `6 P t: H# a4 n# X
- <div>/ t- T9 F0 i$ k
- <div class="hit-name">2 ?8 T8 B) |& ^# w
- <!--{{#helpers.highlight}}{ "attribute": "name" }{{/helpers.highlight}}-->
$ [! m8 s0 X' ` - {{#helpers.highlight}}{ "attribute": "overview" }{{/helpers.highlight}}+ q" m7 v5 |; x6 P( F4 l
- ({{#helpers.highlight}}{ "attribute": "id" }{{/helpers.highlight}})
" j* f/ P# ]7 J' Y - </div>
- J$ _4 y$ `, V, B - </div>
6 ]8 Y9 z- t2 H1 H4 j - `,
# K, w0 l/ O% L; g! X1 n) x3 \ - },
g' k( ?& b5 J" O - }),
; [" |( A# y8 o) F - ])3 s: C, s* [) G p7 b
* Z' t: r: K5 @$ Z6 s$ X$ ^5 V3 f- search.start()
复制代码
# b) l. y6 v7 ~+ V- k; G& F5 j, _3 d
" W: d& l. _ _ j2 Y5 d5 _' U搜索界面简陋一点
- H7 ], W, N$ A: ~( ]) U6 ] |
|