mirror of
https://github.com/apache/zeppelin
synced 2026-05-24 09:38:26 +00:00
ZEPPELIN-501: Indexing notebook names
This commit is contained in:
parent
b853aa64de
commit
e80c3e5f8c
2 changed files with 40 additions and 0 deletions
|
|
@ -198,6 +198,7 @@ public class SearchService {
|
|||
*/
|
||||
void indexDocs(final IndexWriter writer, Collection<Note> notes) throws IOException {
|
||||
for (Note note : notes) {
|
||||
indexDoc(writer, note.getId(), note.getName());
|
||||
for (Paragraph doc : note.getParagraphs()) {
|
||||
if (doc.getText() == null) {
|
||||
LOG.info("Skipping empty paragraph");
|
||||
|
|
@ -209,6 +210,15 @@ public class SearchService {
|
|||
writer.commit();
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes a notebook name
|
||||
* @throws IOException
|
||||
*/
|
||||
private void indexDoc(IndexWriter w, String noteId, String noteName) throws IOException {
|
||||
Document doc = newDocument(noteId, noteName);
|
||||
w.addDocument(doc);
|
||||
}
|
||||
|
||||
/**
|
||||
* Indexes a single paragraph = document
|
||||
*/
|
||||
|
|
@ -232,6 +242,20 @@ public class SearchService {
|
|||
return doc;
|
||||
}
|
||||
|
||||
//TODO(bzz): refactor and re-use code from above
|
||||
private Document newDocument(String noteId, String noteName) {
|
||||
Document doc = new Document();
|
||||
|
||||
Field pathField = new StringField(ID_FIELD, noteId, Field.Store.YES);
|
||||
doc.add(pathField);
|
||||
|
||||
doc.add(new StringField("title", noteName, Field.Store.YES));
|
||||
|
||||
//doc.add(new LongField("modified", date.getTime(), Field.Store.NO));
|
||||
doc.add(new TextField(SEARCH_FIELD, noteName, Field.Store.YES));
|
||||
return doc;
|
||||
}
|
||||
|
||||
/**
|
||||
* ID looks like '<note-id>/paragraph/<paragraph-id>'
|
||||
*
|
||||
|
|
|
|||
|
|
@ -47,6 +47,22 @@ public class SearchServiceTest {
|
|||
String.format("%s/paragraph/%s", note2.getId(), note2.getLastParagraph().getId()));
|
||||
}
|
||||
|
||||
@Test public void canIndexAndQueryByNotebookName() {
|
||||
//given
|
||||
Note note1 = newNoteWithParapgraph("Notebook1", "test");
|
||||
Note note2 = newNoteWithParapgraphs("Notebook2", "not test", "not test at all");
|
||||
notebookIndex.index(Arrays.asList(note1, note2));
|
||||
|
||||
//when
|
||||
List<Map<String, String>> results = notebookIndex.search("Notebook1");
|
||||
|
||||
//then
|
||||
assertThat(results).isNotEmpty();
|
||||
assertThat(results.size()).isEqualTo(1);
|
||||
assertThat(results.get(0)).containsEntry("id", note1.getId());
|
||||
}
|
||||
|
||||
|
||||
@Test //(expected=IllegalStateException.class)
|
||||
public void canNotSearchBeforeIndexing() {
|
||||
//given no notebookIndex.index() was made
|
||||
|
|
|
|||
Loading…
Reference in a new issue