定制 decatur-vote/web-search 二次开发

按需修改功能、优化性能、对接业务系统,提供一站式技术支持

邮箱:yvsm@zunyunkeji.com | QQ:316430983 | 微信:yvsm316

decatur-vote/web-search

Composer 安装命令:

composer require decatur-vote/web-search

包简介

A small library to easily add search support to a website, with a built-in search gui.

README 文档

README

Web Search

This is the Search software for DecaturVote.com. Built with taeluf/liaison and taeluf/big-db.

Under Development - This search library is functional, but it is still under development. We haven't documented anything tag-related. Some features may change or break.

See an early example on youtube.

Install

composer require decatur-vote/web-search v1.0.x-dev   

or in your composer.json

{"require":{ "decatur-vote/web-search": "v1.0.x-dev"}}  

Routes

At this time, route cannot be changed, because it is hardcoded in the javascript and PHP form.

  • GET /search/: Load search page (html) with most recent search items
  • GET /search/?q=Some+Query: Load search page (html) with results from the query q
  • GET /search/?format=json&q=Some+Query: Get a json array of rows matching the query. The built-in search script uses this. Contains:
    • uuid - the item's uuid
    • uri - the url for the item. Typically a /rel/url for items on the same site, but can be a full url.
    • title - The title of the item
    • summary - A 300 character summary of the item. (Search supports 1024 chars in the database, but only sends 300 characters to the browser. Well, 303 if you count the ... at the end).
    • created_at - mysql compatible datetime string
    • updated_at - user friendly format of Y-m-d g:i a

Usage

Adding & deleting search items is very easy, and you can even use SearchDb on its own to create your own GUI for search results.

Typically, you'll also want to do the Setup steps below.

Examples:

<?php  
// $pdo = new \PDO(...)  
$searchDb = new \DecaturVote\SearchDb($pdo);  
  
// add searchable items to the index.  
$searchDb->add_searchable($uuid=uniqid('search'), 'Title 1 x', 'Summary v', '/article/title/1/');  
$searchDb->add_searchable(uniqid('search'), 'Title 2 v', 'Summary x', '/article/title/2/');  
$searchDb->add_searchable(uniqid('search'), 'Title 3 y', 'Summary r', '/article/title/3/');  
  
// get an array of `DecaturVote\SearchDb\Search` items (they are BigOrm subclasses)  
$items  = $searchDb->search("x"); # returns the first & 2nd item in that order, since they both contain x & title takes precedent.   
  
// delete an item by uuid  
$searchDb->delete_from_search($uuid);  

Setup

To setup the Search: Initialize the database, Set it up with Liaison, style it, and add an Integration class for needed callbacks.

See DecaturVote.com integrations for an example.

Initialize the database

Run this command in your CLI

vendor/bin/dv-search create-db -pdo path/to/pdo.php  

You MUST create the file path/to/pdo.php and have it return a PDO instance. The table will be created with that instance.

Setup with Liaison

<?php  
$integration = new \DecaturVote\Search\Test\SearchIntegration($pdo);  
$site_app = new \DecaturVote\Search\LiaisonPackage($lia, $integration);  
  
$lia->addResourceFile(\Tlf\Js\Autowire::filePath());  

Setup Integration

Define MyIntegrationClass. See DecaturVote.com integrations for an example. It must implement DecaturVote\Search\IntegrationInterface:

<?php  
  
namespace DecaturVote\Search;  
  
interface IntegrationInterface {  
    /** get a valid PDO instance */  
    public function getPdo(): \PDO;  
  
    /** Get an array of RSS channel information, per the 2.0 RSS spec. See https://validator.w3.org/feed/docs/rss2.html */  
    public function getRssChannel(): array;  
  
    /** get a schem & host (like `https://example.com`) to prepend to any relative urls in your search items, primarily for rss */  
    public function getHostWebsite(): string;  
  
    /** called when the page view is loaded. You should use this to add your own styles.   
     *  
     * @param $lia the liaison instance  
     */  
    public function page_will_display(\Lia $lia): void;  
  
    /**  
     * Called when the view `search/tag-feed` is loaded. Use this to add styles.  
     */  
    public function tag_feed_will_display(\Lia $lia): void;  
  
    public function add_tag_will_display(\Lia $lia): void;  
  
    /**   
     * Check if tag creation is allowed for current user.  
     *  
     * @param $lia liaison instance  
     * @param $tag The tag that will be created, if allowed  
     *  
     * @return true if creation allowed, false if not.  
     */  
    public function can_create_tag(\Lia $lia, \DecaturVote\SearchDb\Tag $tag): bool;  
}  

Styling

No styles are provided within. See DecaturVote.com integrations for an example. Here is a css template file for you to fill in.

/** The root node. Contains an h1, form and div.ResultsList */  
.DecaturVoteSearch {  
    --selected_button_color: green;  
}  
/** Search page heading */  
.DecaturVoteSearch h1 {}  
  
/** Parent Node for each .SearchResult */  
.DecaturVoteSearch .ResultsList {}  
  
/** Container for search result (child of .ResultsList) */  
.DecaturVoteSearch .SearchResult {}  
  
/** heading for each search result */  
.DecaturVoteSearch .SearchResult h2 {}  
/** search result title link */  
.DecaturVoteSearch .SearchResult h2 a {}  
/** search result title link, hover/active */  
.DecaturVoteSearch .SearchResult h2 a:hover, .DecaturVoteSearch .SearchResult h2 a:active, .DecaturVoteSearch .SearchResult h2 a:focus {}  
/** Summary of search result items */  
.DecaturVoteSearch .SearchResult > p {}  
  
.DecaturVoteSearch nav.pages a {  
    display:inline-block;  
    padding:4px;  
    margin:4px;  
}  
.DecaturVoteSearch nav.pages a.current_page {  
    text-decoration:none;  
}  
  
.DecaturVoteSearch a.reset_search {  
    font-style:italic;  
}  
  
.DecaturVoteSearch .SearchResult .search_footer {  
    display:flex;  
    flex-direction:row;  
    justify-content:space-between;  
}  
  
/** The datetime in the bottom-right corner of the result */  
.DecaturVoteSearch .SearchResult .date {  
    margin-right:8px;  
    margin-top:8px;  
}  
  
/** The item's type in the bottom-left corner of the result */  
.DecaturVoteSearch .SearchResult .type{  
    margin-right:8px;  
    margin-top:8px;  
}  
  
/** the search form */  
.DecaturVoteSearch form {}  
/** the search form's input */  
.DecaturVoteSearch form input {}  
  
.DecaturVoteSearch form button.SearchTagButton.selected {  
    background: var(--selected_button_color);  
}  

Testing

Setup Mysql test settings

At the root of Search, create the file mysql_settings.json and fill it in with your development environment settings:

WARNING: Running tests will delete your search indices from your database

{  
    "database": "dbname",  
    "host": "localhost",  
    "user": "user_name",  
    "password": "bad_password"  
}  

Then run vendor/bin/phptest.

We currently don't have a Liaison integration in this repo, so testing in your browser is not available.

Screenshots

These are from DecaturVote.com/search/. Styled by the DecaturVote.com integrations

/search/:
A 'Search' Heading, a search input box, and four search results in a vertical list, each showing a title, summary, and date + time. This screenshot shows design, and is not intended to share text-content. Some names are redacted with black boxes.

decatur-vote/web-search 适用场景与选型建议

decatur-vote/web-search 是一款 基于 PHP 开发的 Composer 扩展包,目前已累计 29 次下载、GitHub Stars 达 0, 最近一次更新时间为 2023 年 05 月 30 日, 在 PHP 生态内属于活跃度较高的组件。

我们在过去多个企业项目中使用过 decatur-vote/web-search 或与其功能相近的方案,如果你在选型或落地过程中遇到问题,例如 版本兼容、二次改造、私有化封装、与内部系统对接、生产 BUG 排查,欢迎联系我们协助评估。

围绕 decatur-vote/web-search 我们能提供哪些服务?
定制开发 / 二次开发

基于 decatur-vote/web-search 在你已有业务上做功能扩展、字段裁剪、UI 适配、与内部账号 / 权限 / 日志系统的深度对接。

BUG 修复 & 性能优化

线上偶发问题、内存泄漏、慢查询、并发异常等排查修复;针对高流量场景做缓存、队列、索引层面的调优。

项目外包 & 长期维护

承接完整的项目从需求 → 设计 → 开发 → 上线 → 长期运维;也可按月提供技术保姆服务。

yvsm@zunyunkeji.com QQ:316430983 微信:yvsm316 西安尊云信息科技 · 专注 PHP / Go / 分布式系统研发

统计信息

  • 总下载量: 29
  • 月度下载量: 0
  • 日度下载量: 0
  • 收藏数: 0
  • 点击次数: 7
  • 依赖项目数: 0
  • 推荐数: 0

GitHub 信息

  • Stars: 0
  • Watchers: 0
  • Forks: 0
  • 开发语言: PHP

其他信息

  • 授权协议: MIT
  • 更新时间: 2023-05-30