Skip to content

Commit

Permalink
Merge pull request #1 from Infosys/docsearch
Browse files Browse the repository at this point in the history
Docsearch
  • Loading branch information
amrishraje authored Oct 30, 2020
2 parents 717419e + 838b1aa commit 14e4fcd
Show file tree
Hide file tree
Showing 7 changed files with 366 additions and 83 deletions.
6 changes: 4 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
# CouchbaseLiteTester
###### version 1.4
###### version 1.5
This app provides a UI to create a local Couchbase Lite DB and Sync Data to the DB from a Couchbase Sync Gateway. It provides features to search for documents in the CBLite DB, selectively sync certain channels and supports both Pull and Push replication.

## Getting Started
Expand Down Expand Up @@ -88,6 +88,8 @@ mvn compile package
This will create a distributable JAR file in build folder. Package an appropriate defaults.xml file along with your jar file with appropriate environments setup.

## Features
###### version 1.5
* Support to search documents (Advance Search) based on multiple keywords
###### version 1.4
* Support for adding Attachments (Blobs) to Documents in CBLite Tester and syncing it up to the server
###### version 1.3
Expand All @@ -113,7 +115,7 @@ This will create a distributable JAR file in build folder. Package an appropriat
* Support to edit data in the UI and do 'push' replication to sync gateway

## Future roadmap
* Support to search documents based on specified criteria
* ~~Support to search documents based on specified criteria~~ (implemented in v1.5)
* Support to delete documents from CBLite via UI and sync deletes to CB Server
* Support to run N1QL like queries on CBLite DB
* Support to create/delete users on Sync Gateway and grant access to channels
Expand Down
5 changes: 5 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -131,5 +131,10 @@
<artifactId>javafx-base</artifactId>
<version>13</version>
</dependency>
<dependency>
<groupId>org.ahocorasick</groupId>
<artifactId>ahocorasick</artifactId>
<version>0.4.0</version>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,66 @@
package io.amrishraje.cblitetester;

import javafx.collections.transformation.FilteredList;
import javafx.event.ActionEvent;
import javafx.scene.control.*;
import javafx.stage.Stage;
import org.ahocorasick.trie.Emit;
import org.ahocorasick.trie.Trie;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.Arrays;
import java.util.Collection;
import java.util.Map;

public class AdvanceSearchController {

private static final Logger logger = LoggerFactory.getLogger(AdvanceSearchController.class);
public Button cancelButton;
public TextArea searchArea;
public TextField searchTextBox;
public CheckBox matchWholeWords;
public Button searchButton;
public Label searchStatusLabel;
MainController mainController;
private FilteredList<Map.Entry<String, String>> filteredData;

public void setMainController(MainController mainController) {
this.mainController = mainController;
}

public void cancelSearch(ActionEvent event) {
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
}

public void searchDocuments(ActionEvent event) {
filteredData = mainController.getFilteredData();
String lowerCaseFilter = searchTextBox.getText();
String[] searchList = lowerCaseFilter.split(";");
filteredData.setPredicate(tableData -> {
return containsWordsAhoCorasick(tableData.getValue(), searchList, matchWholeWords.isSelected());
});
Stage stage = (Stage) cancelButton.getScene().getWindow();
stage.close();
}

public static boolean containsWordsAhoCorasick(String inputString, String[] words, Boolean matchWholeWord) {
Trie trie;
if (matchWholeWord) {
trie = Trie.builder().onlyWholeWords().ignoreCase().addKeywords(words).build();
} else {
trie = Trie.builder().ignoreCase().addKeywords(words).build();
}
Collection<Emit> emits = trie.parseText(inputString);
boolean found = true;
for(String word : words) {
boolean contains = Arrays.toString(emits.toArray()).contains(word.toLowerCase());
if (!contains) {
found = false;
break;
}
}
return found;
}
}
Loading

0 comments on commit 14e4fcd

Please sign in to comment.