[openstreetmap/openstreetmap-website] Add search box to diaries page (#3289)
Emin Kocan
notifications at github.com
Tue Aug 27 13:19:26 UTC 2024
### Progress on Implementing Search for Diaries
I've explored several approaches to add search functionality to the diaries page. Here’s a summary of what has been done so far, along with some considerations and questions moving forward:
1. **PostgreSQL `LIKE` Text Searching:**
- **Method:** Implemented a basic text search using PostgreSQL’s `LIKE` operator.
- **Results:** This method is fast and responsive, but the relevance of the results may not be ideal since `LIKE` searches do not inherently provide any ranking mechanism.
- **Code Example:**
```ruby
entries = entries.where("title LIKE :query OR body LIKE :query", query: search_query)
```
2. **Using the `pg_search` Gem:**
- **Method:** Integrated the `pg_search` gem to enable full-text search capabilities.
- **Results:** This allows for more sophisticated search capabilities, including relevance ranking and partial word matching. However, with around 600,000 entries in the database, this approach has shown to be quite slow.
- **Code Example:**
```ruby
include PgSearch::Model
pg_search_scope :search_by_title_and_body,
against: [:title, :body],
using: {
tsearch: { prefix: true } # Enables partial word matching
}
entries = entries.search_by_title_and_body(params[:search])
```
3. **Exploring Trigram Indexes in PostgreSQL:**
- **Next Steps:** We’re considering the use of trigram indexes (`pg_trgm` extension) to accelerate text searches while still offering some level of relevance ranking. This approach could provide a balanced solution between performance and relevance. However, it would require creating additional database migrations to index both the `title` and `body` fields, which would add a layer of complexity to the project. The question here is whether we are comfortable with introducing this complexity. Are we okay with the trade-offs involved?
4. **External Search Engines (DuckDuckGo, etc.):**
- **Consideration:** Another approach could involve leveraging external search engines like DuckDuckGo by parsing user input and redirecting to search results. This would expose users to privacy-focused search engines and could potentially offload the search functionality. However, this approach has significant downsides, including the delay in indexing by these engines and a lack of control over when and how content is indexed.
### Main Questions
- **Time Investment:** How much time are we willing to invest in this feature? The implementation options vary greatly in complexity and development time.
- **Relevance vs. Performance:** How important is the relevance of search results compared to the speed of search? Should we prioritize one over the other?
Your feedback on these considerations would be valuable in deciding the best path forward. Thank you.
--
Reply to this email directly or view it on GitHub:
https://github.com/openstreetmap/openstreetmap-website/issues/3289#issuecomment-2312543049
You are receiving this because you are subscribed to this thread.
Message ID: <openstreetmap/openstreetmap-website/issues/3289/2312543049 at github.com>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.openstreetmap.org/pipermail/rails-dev/attachments/20240827/6ca27ffb/attachment-0001.htm>
More information about the rails-dev
mailing list