Version 12 (modified by mitex, 16 years ago) (diff) |
---|
Analysis
Overview
The goal of this task is to provide the ability for the user to search the content of the book.
We could make this live search in some of the next revisions, for now the search will be evoked from button or enter key (while the focus is set to the text input field)
It will be nice to have the ability to search resources by their name or meta data in this palette. (From the server and from all open books). And appropriate interface for that.
In this revision:
- The Tools tab has a Search palette. It lets the user search a Sophie book.
- A text field is available at the top of the palette where a user can enter a word or phrase he wants to find in current book.
- Search button will be available next to the text field.
- Below them next and previous buttons should be available.
- The searching palette in the Tools tab provides a list of results with context (some words before and after the match; also the page number).
- The order of the results is the following one:
- Results from different pages are placed from top to bottom with the order of the page number.
- If the results are in single page they appear sorted by the type of the component that holds them
- EXAMPLE: 3 results are available on the same page. One of them comes from text frame, one of them comes from embedded book and the third comes from text frame inside of a group. So on the top is the results from the text frames, after this comes the result from the group and on the bottom seats the result from the embedded book.
- If the results are on the same page and come from the same type of components they are ordered by the z-order of their holders.
- If the results come from one component they are ordered by their appearance in it.
- EXAMPLE: If they are 2 results inside single text frame, they should be ordered from top to bottom. The first one is the one on top etc.
- EXAMPLE: If the results come from embedded book the rules described above are applied to them.
Typical scenario:
- Text is typed in the field at the top of the palette.
- Enter is hit.
- A list of all occurrences in text are provided in the palette.
- All occurrences are highlighted in the text.
- The first result is selected(focused).
- The list itself provides selection(focus) functionality same as previous/next buttons.
- Clicking on a result displays the page of the book with the match.
- The caret is positioned at the beginning of the match.
- The match is selected.
- Searching should be available in both Author and Reader.
Task requirements
- Provide the ability for the user to search the text content for currently opened book.
- Add a "Search" button next to the search box in the palette.
- Make the list to display all occurrences in text. Each list item should contain:
- the page number of the match
- a ":" sign
- three (or less, if less words are available or if they are longer than 50 chars) words before the match
- the match
- and three (or less, applying the same rule) words after the match.
- OPTIONAL: If occurrences are more than 100, only first 100 should be displayed.
Task result
- Source code
Implementation idea
- Use LogicR3Button for the button.
- Use the firstSelectedItem property in ListPalette.
- Extend ListPaletteItem and implement there the logic for displaying a given match.
- A hash-search algorithm can be used when searching larger fragments.
Related
- SEARCH_COMMONS_R0 - for highlighting
How to demo
- Insert a text frame and write something like "dfjkfds abc jfkdjfslk-abc-fdjfslkdfs" (at least two occurrencies of "abc")
- Open the search palette
- Search for "abc"
Design
- Create a module org.sophie2.main.func.search.
- Add its name to both author.bundles.config and reader.bundles.config.
- Create class SearchModule that extends SophieModule.
- Add it in both FakeAuthorMain and FakeReaderMain.
- In ListPalette:
- Add enum EventIds with the following item:
- ITEM_SELECTED
- In the selection listener of the ListSelectionModel of the palette:
- Fire ITEM_SELECTED event.
- Add enum EventIds with the following item:
- Move the search palette to org.sophie2.main.func.search.view package.
- Rename the @SkinElementId to match the new module name.
- Add the palette as an extension.
- Add enum EventIds with the following items:
- BOOK_SEARCH - Searches in current book.
- PALETTE_PREV, PALETTE_NEXT - Selects the previous/next search match in the search palette.
- Add new "Search" LogicR3Button to the JComponent in initHead().
- Place the button next to the search textbox.
- It should fire BOOK_SEARCH event.
- Add "<<" and ">>" LogicR3Buttons below the text box and the search button.
- Highlighting:
- TODO ...
- Create a new immutable class org.sophie2.main.func.search.model.SearchMatch
- TODO: fields/properties ...
- Create enum org.sophie2.main.func.search.logic.SearchLogic
- BOOK_SEARCH:
- TODO ...
- TODO algorithm ...
- ITEM_SELECTED:
- Invoked when a search match is selected (via a mouse click, pressing Up/Down arrow keys or by pressing a Prev/Next button)
- TODO: moves the caret ...
- PALETTE_PREV:
- Sets firstSelected of the search palette to the previous match (if current is not first match in the list).
- Fire ITEM_SELECTED event.
- PALETTE_NEXT:
- analogical to PALETTE_PREV.
- Register the operations as extensions.
- BOOK_SEARCH:
- Remove obsolete classes:
* org.sophie2.main.app.model.frame.text.util.SearchMatch
- org.sophie2.main.app.model.book
Implementation
Testing
(Place the testing results here.)
Comments
(Write comments for this or later revisions here.)