The design and implementation of a search engine based on java web based on software engineering [source code + paper]


foreword

Today, seniors share with you a graduation design project:

Design and Implementation of Search Engine Based on Java Web

Project acquisition:
https://gitee.com/sinonfin/L-javaWebSha

1. Project design

1. Modular design

After studying the search engine and combining it with Lucene's own characteristics, the functions that need to be implemented in this design are described as follows:

  • Support desktop file search, formats include txt, doc, xls and ppt;
  • Support word segmentation query
  • Support full text search
  • Ability to highlight search keywords
  • Show time spent on query
    Show search history, filter keywords

Word segmentation query and full-text search, we can use Lucene’s own library and related algorithms to complete the design. In order to solve the problem of keyword highlighting, obviously, we need to use Highlighter’s Auxiliary, save data through database persistence.

When we conduct requirements analysis, the formulated use cases and domain models can be directly brought into the design phase. The structure of our roughly designed search engine system is as follows:
insert image description here

2. Realize the effect

insert image description here
insert image description here

insert image description here
insert image description here

There are many functions, and the seniors will not show them one by one here.

2. Part of the source code

There are many source codes and the length of the article is limited, so I won’t post them here, and only show a small part of the key code

Some code examples:

/**   
* 为数据库检索数据创建索引   
* @param rs   
* @throws Exception   
*/    
    private void createIndex(ResultSet rs) throws Exception {
    
         
        Directory directory = null;     
        IndexWriter indexWriter = null;     
         
        try {
    
         
            indexFile = new File(searchDir);     
            if(!indexFile.exists()) {
    
         
                indexFile.mkdir();     
            }     
            directory = FSDirectory.open(indexFile);     
            analyzer = new IKAnalyzer();     
              
            indexWriter = new IndexWriter(directory, analyzer, true, IndexWriter.MaxFieldLength.UNLIMITED);     
            indexWriter.setMaxBufferedDocs(maxBufferedDocs);     
            Document doc = null;     
            while(rs.next()) {
    
         
                doc = new Document();     
                Field id = new Field("id", String.valueOf(rs.getInt("id")), Field.Store.YES, Field.Index.NOT_ANALYZED, TermVector.NO);     
              
               // Field title = new Field("title", rs.getString("title") == null ? "" : rs.getString("title"), Field.Store.YES,Field.Index.ANALYZED, TermVector.NO);  
                Field content = new Field("content", rs.getString("content") == null ? "" : rs.getString("content"), Field.Store.YES,Field.Index.ANALYZED, TermVector.NO);   
                doc.add(id);     
            
                doc.add(content);     
                indexWriter.addDocument(doc);     
            }                              
            indexWriter.optimize();     
            indexWriter.close();     
        } catch(Exception e) {
    
         
            e.printStackTrace();     
        }      
    }  

Project source code

Project acquisition:
https://gitee.com/sinonfin/L-javaWebSha

Guess you like

Origin blog.csdn.net/mojikopi/article/details/131976781