简体   繁体   中英

how highlight a word from result of search query

I have a trouble to make a highlight from search result this is my code (python file)

#proses cari artikel
@app.route('/pakar/hasil_artikel', methods=['GET', 'POST'])
def hasil_artikel_pakar():
halaman = 'cari artikel'
iduser = session.get('id_user')
cari = request.form['cari']
cari_kecil = cari.lower()
cari_clear =  cari_kecil.split()

data_model = "model/idwiki_word2vec_100.model"
model_baru = gensim.models.Word2Vec.load(data_model)
hasil = model_baru.most_similar(positive=cari_clear)

y = ' '.join('{}'.format(*el) for el in hasil)
x = cari+ " " + y
z = x.split(" ")

cursor1 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor1.execute('SELECT * FROM user WHERE id_user = %s', (iduser,))
sesinfo = cursor1.fetchone()

cursor2 = mysql.connection.cursor(MySQLdb.cursors.DictCursor)
cursor2.execute('SELECT * FROM artikel JOIN user ON artikel.id_user = user.id_user WHERE artikel.judul_artikel LIKE %s OR artikel.isi_artikel LIKE %s', ("%" + z[0] + "%","%" + z[0] + "%",))
artikel = cursor2.fetchall()

return render_template('pakar/hasil_artikel.html', hasil=hasil, hal=halaman, sesinfo=sesinfo, artikel=artikel, cari=cari)

and this is my code (html code)

<div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
{% for artikels in artikel %}
                <div class="card">
                    <div class="header bg-red">
                        <h2>
                            {{ artikels.judul_artikel }}
                        </h2>
                        <ul class="header-dropdown m-r--5">
                            <i class="material-icons">person</i><span> Ditulis Oleh : {{ artikels.nama }} </span>
                        </ul>
                    </div>
                    <div class="body">
                    <img src="/static/foto_artikel/{{ artikels.foto_artikel }}" width="100px" height="100px"><br><br>    
                    <b>Tanggal Pembuatan Artikel : {{ artikels.tanggal_artikel.strftime('%d %B %Y') }}</b><br><br>
                    {{ artikels.isi_artikel | truncate(500) | safe }}<a href="/pakar/baca_artikel/{{ artikels.id_artikel }}" class="btn btn-success"> Baca Selengkapnya</a>    
                    </div>
                </div>          
{% endfor %}
            </div>

The problem is, How to Make A Highlight From The Result Of That Like CTRL+F in Browser? thank you for attention

use the link tag that will help you get the highlighted version

thank you for your attention finally i found my problem solving for this question

i using jquery highlight plugin

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM