kassiscore

package module
v0.1.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Jul 24, 2022 License: MIT Imports: 24 Imported by: 0

README

kassis

本アプリ(kassis) は、PDFやらエクセルファイルなどを検索するためのものです。

概要

ファイルを読んで索引化し、ブラウザで検索することが出来ます。

サポートしているファイルは以下のフォーマットです。

  • Excel (拡張子xlsx)
  • Word (拡張子docx)
  • PDF (拡張子pdf)
  • Text (拡張子txt)
読み

「カシス」です。カシスオレンジ(Cassis and Orange)のカシスと同じです。

必要なもの

  • Java Runtime Environment (JRE) version 1.8 以上
  • Go 1.18
  • OS: 以下動作確認済み
    • Windows系: Windows 11
    • Linux系: Ubuntu Server 22.04 LTS

MAC OS X 系については、確認環境が無いため不明ですが、たぶん動くかと。

以下のミドルウェアは、準備段階で本アプリがダウンロードします。 既存で構築していあるものに追加は可能です。

  • Apache Solr 8.11.x
  • Apache Tika 2.4.x (standard server版)

検索および結果を見るためにはブラウザが必要です。

  • Google Chrome 最新版 (Firefox や Edge では確認していません)

環境構築

準備その1

Ubuntu 22.04 LTS 向け
sudo apt update && sudo apt upgrade -y
sudo apt install -y openjdk-17-jre-headless
sudo apt install -y golang-go
sudo apt install -y git
Windows 11 向け
  • JDK のインストール
  • Go のインストール
    • 以下のページより Go 1.18 をダウンロードする(ファイル名:go1.18.4.windows-amd64.msi)
    • インストールする
    • PATHを設定する
  • git for windows のインストール
    • 以下のページより git for windows をダウンロードする(ファイル名:Git-2.37.1-64-bit.exe)
    • インストールする
  • ここまでにインストールしたアプリケーションがインストールされているかを確認する。
    • コマンドプロンプトを起動し、java と go が起動するか確認する。

準備その2

本アプリ(kassis) をダウンロードし、設定を行います。 Apache Tika と Apache Solr は、準備中にダウンロードするので別途ダウンロードする必要はありません。

git clone https://github.com/nakamura-akifumi/kassis.git
cd kasis
go run cmd/configurator/main.go makeconfigset
go run cmd/configurator/main.go downloadapp
go run cmd/configurator/main.go startsolr
go run cmd/configurator/main.go setupsolr
go run cmd/configurator/main.go starttika

以下のコマンドを実行して、問題が無いか確認します。

go run cmd/configurator/main.go

実行

ファイルのインポート

go run cmd/import/main.go <ファイル名もしくはフォルダ名>

検索および結果表示

go run cmd/webserver/main.go

ブラウザで localhost:1323 にアクセスします。

技術的内容

solrのデータ再構築手順
.\bin\solr delete -c kassiscore
.\bin\configurator -setup-solr
ディレクトリ構成図
  • root
    • bin
    • config
    • tools
    • web
      • assets
      • public
      • views
データフロー

(あとで記載予定)

実行ファイルの作成方法(ビルド方法)

make が動くこと。 実行ファイル(バイナリファイル)は、bin に作成されます。

準備(Windows の場合)

実行環境に加えて以下のものを準備する必要がある

(windowsで実行する場合は以下のツールが必要)

準備(Ubuntu 22.04 LTS の場合)

sudo apt install make 

ビルド

windowsの場合は、git bash 上で実行してください。

make build 

テスト

Goでのテスト
go test github.com/nakamura-akifumi/kassis/...
実行ファイルをテスト

(あとで考える。自動テストしたい)

Author, Contributor

Akifumi NAKAMURA (@tmpz84)

LICENSE

MIT

Documentation

Index

Constants

View Source
const (
	MSGINFO  = false
	MSGERROR = true
)
View Source
const ContenttypeExcel string = "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
View Source
const ContenttypePdf string = "application/pdf"
View Source
const ContenttypeText string = "text/plain"
View Source
const ContenttypeWord string = "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
View Source
const NGLBL = "\u001B[31mNG\u001B[0m"
View Source
const OKLBL = "\u001B[32mOK\u001B[0m"
View Source
const SOLRAPPURL = "https://www.apache.org/dyn/closer.lua/lucene/solr/8.11.2/solr-8.11.2.zip?action=download"
View Source
const TIKAAPPURL = "https://dlcdn.apache.org/tika/2.4.1/tika-server-standard-2.4.1.jar"

Variables

View Source
var (
	VERSION  = "0.1.0"
	REVISION = ""
)
View Source
var ConfigFileName = "config.json"
View Source
var DisplayModeOnCheckFunction = "error-only"

Functions

func ArrayContains

func ArrayContains(arr []string, str string) bool

ArrayContains は、配列の中に特定の文字列が含まれるかを返す

func CheckConfigAndConnections

func CheckConfigAndConnections(displaymode string)

CheckConfigAndConnections は、設定が正しいかをチェックする関数です。 display mode : full or error-only

func Copy

func Copy(srcFile, dstFile string) error

func CopyDirectory

func CopyDirectory(scrDir, dest string) error
func CopySymLink(source, dest string) error

func CreateIfNotExists

func CreateIfNotExists(dir string, perm os.FileMode) error

func DownloadApps

func DownloadApps()

func DownloadFile

func DownloadFile(filepath string, url string) error

func Exists

func Exists(filePath string) bool

func ExtnameToMediaType

func ExtnameToMediaType(extname string) string

func GenerateDefaultConfigSet

func GenerateDefaultConfigSet()

func GenerateExcelIndex

func GenerateExcelIndex(si *solr.SolrInterface, filename string, mediatype string, doc *goquery.Document) string

GenerateExcelIndex は Excel(.xlsx)形式のファイルの索引を作る Excelの1行で Solr の1ドキュメントとする

func GeneratePdfIndex

func GeneratePdfIndex(si *solr.SolrInterface, filename string, mediatype string, doc *goquery.Document) string

GeneratePdfIndex は、PDF(.pdf)形式のファイルの索引を作る PDFの1ページで Solr の1ドキュメントとする

func GenerateTextIndex

func GenerateTextIndex(si *solr.SolrInterface, filename string, mediatype string, doc *goquery.Document) string

GenerateTextIndex は、テキスト形式のファイルの索引を作成します 1ファイルで Solr の1ドキュメントとする

func GenerateWordxIndex

func GenerateWordxIndex(si *solr.SolrInterface, filename string, mediatype string, doc *goquery.Document) string

GenerateWordxIndex は MS WORD(.docx)形式のファイルの索引を作る 1ファイルで Solr の1ドキュメントとする

func HandlerGetMaterials

func HandlerGetMaterials(c echo.Context) error

func ImportFromFile

func ImportFromFile(files []string, tikaserveruri string, solrserveruri string, solrcorename string) error

func SetupSolr

func SetupSolr(corename string) error

func SolrAddDocument

func SolrAddDocument(si *solr.SolrInterface, materialid string, objecttype string, contents []string, vparams map[string]string) error

func SolrClearDocument

func SolrClearDocument(uriaddress string, corename string) error

func SolrQuery

func SolrQuery(uriaddress string, corename string, qs string) (*solr.SolrResult, error)

SolrQuery は、Solrに検索を投げます TODO: 引数要改良 、solrに接続する箇所も改良。毎回接続するのは問題。

func SolrSchemaUpdate

func SolrSchemaUpdate(uri string, corename string, schemafilename string) error

func SolrServerPing

func SolrServerPing(uri string) (string, error)

func StartSolr

func StartSolr(cfg *KENVCONF)

func StartTika

func StartTika(cfg *KENVCONF) error

func StopSolr

func StopSolr(cfg *KENVCONF)

func StopTika

func StopTika(cfg *KENVCONF) error

func TikaPing

func TikaPing(tikauri string) (string, error)

func Unzip

func Unzip(src, dest string) error

func WebCrawler

func WebCrawler(uri string, cfg *KENVCONF) (string, error)

Types

type FileProcessor

type FileProcessor struct {
	Filenamematch    string   `json:"filenamematch"`
	Excludesheetname []string `json:"excludesheetname"`
}

type KENVCONF

type KENVCONF struct {
	HomeDir   string `json:"homeDir"`
	ExtDir    string `json:"extDir"`
	ExtAppDir string `json:"extAppDir"`
	WebServer struct {
		Listen string `json:"listen"`
	} `json:"web"`
	Solr struct {
		Home      string `json:"home"`
		Serveruri string `json:"serveruri"`
		Corename  string `json:"corename"`
	} `json:"solr"`
	Tika struct {
		Home      string `json:"home"`
		Serveruri string `json:"serveruri"`
	} `json:"tika"`
	Files []FileProcessor `json:"files"`
}

func LoadConfig

func LoadConfig() *KENVCONF

type KWQIF

type KWQIF struct {
	QueryString  string
	QueryMessage string
	NumOfPage    int
	Curretpage   int
	Lastpage     int
}

KWQIF は、Web用のレスポンス構造体

type KWRIF

type KWRIF struct {
	NumFound        int
	ResponseStatus  string
	ResponseMessage string
	KQ              KWQIF
	Materials       []Material
}

type Material

type Material struct {
	ID         string   `json:"id"`
	MaterialID string   `json:"materialid"`
	ObjectType string   `json:"objecttype"`
	Foldername string   `json:"foldername"`
	Filename   string   `json:"filename"`
	Sheetname  string   `json:"sheetname"`
	Mediatype  string   `json:"mediatype"`
	Contents   []string `json:"contents"`
	Title      string   `json:"title"`
}

Directories

Path Synopsis
cmd

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL