Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/Vulcan search #94

Open
wants to merge 3 commits into
base: feature/add-vulcan
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
72 changes: 65 additions & 7 deletions vulcan-static/baseScript.js
Original file line number Diff line number Diff line change
@@ -1,16 +1,74 @@
// Apart from removing console.log statements, and the change below, the JS
// files are unchanged compared to those in the original Vulcan repo.

// Original:
// ****************** Start of modified code ******************
// const sio = io();

// Modified:
const sio = io({
query: {
id: window.location.pathname.split("/").pop()
id: window.location.pathname.split("/").pop(),
},
});

/**
* Replace the identifier at the end of the current path and navigate there.
*/
sio.on("route_to_layout", (identifier) => {
const newPath = window.location.pathname
.split("/")
.slice(0, -1)
.concat(identifier)
.join("/");
window.location.href = newPath;
});

/**
* Replace or initialize existing filters and add filters from the server.
*
* SearchFilter objects (backend) need to be converted to FilterInfo objects (frontend).
*
* The FilterInfo constructor takes the following arguments:
* - corpus_slice_name: specifies the name of the graph to filter (e.g. 'gold string')
* - outer_layer_id: specifies the object type to perform the search on (e.g. tokens, graphs, nodes)
* -> See vulcan.search.search_registry.OUTER_SEARCH_LAYERS for a full list.
* - unique_inner_layer_ids: a list of strings specifying the type of filter operations applied (equality check, regex, etc.)
* -> See vulcan.search.search_registry.INNER_SEARCH_LAYERS for a full list.
* - inner_layer_inputs: a mapping (object) from each unique_inner_layer_id to a search argument/parameter for that layer.
*
*/
sio.on("activate_search_filters", (search_filters) => {
if (!search_filters || search_filters.length === 0) {
return;
}

clearSearchFiltersIfEmpty();

const filterInfos = search_filters.map((filter) => {
// Silly, but expected by the FilterInfo constructor.
const uniqueInnerLayerIds = filter["inner_search_layer_names"].map(
(name) => makeUniqueInnerLayerID(name)
);

// Construct a map where the keys are the unique inner layer IDs and
// the values are the corresponding search arguments.
// This works because we the lists of layerIds and arguments are
// guaranteed to have the same length, and the i-th element of each
// list corresponds to the i-th layer of the search filter.
const argumentMap = uniqueInnerLayerIds.reduce((obj, key, index) => {
obj[key] = filter["inner_search_layer_arguments"][index];
return obj;
}, {});

const filterInfo = new FilterInfo(
filter["corpus_slice_name"],
filter["outer_search_layer_name"],
uniqueInnerLayerIds,
argumentMap
);

return filterInfo;
});
filterInfos.forEach((filterInfo) => addSearchFilter(filterInfo));
});

// ****************** End of modified code ******************

// sio.eio.pingTimeout = 120000; // 2 minutes
// sio.eio.pingInterval = 20000; // 20 seconds

Expand Down
35 changes: 31 additions & 4 deletions vulcan-static/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -71,13 +71,36 @@ const EMPTY_SELECTION_TEXT = "-- Select --"
let searchFilters
let searchFilterRects

// ****************** Start of modified code ******************
// function initializeSearchFilters() {
// searchFilters = []
// searchFilterRects = []
// addEmptySearchFilter()
// // addDebuggingSearchFilters()
// }

/**
* Initialize the search filters and search filter rectangles if they have
* not been initialized already.
*/
function initializeSearchFilters() {
searchFilters = []
searchFilterRects = []
addEmptySearchFilter()
clearSearchFiltersIfEmpty()
if (searchFilters.length === 0) {
addEmptySearchFilter()
}
// addDebuggingSearchFilters()
}

function clearSearchFiltersIfEmpty() {
if (!searchFilters) {
searchFilters = []
}
if (!searchFilterRects) {
searchFilterRects = []
}
}
// ****************** End of modified code ******************

function addDebuggingSearchFilters() {
let uniqueid3 = makeUniqueInnerLayerID("NodeContentEquals")
let argsGraph = {}
Expand Down Expand Up @@ -560,6 +583,10 @@ function getInnerLayer(sliceName, outerLayerID, innerLayerID) {

function onSearchIconClick() {
if (!searchWindowVisible) {
// ****************** Start of modified code ******************
initializeSearchFilters()
// ****************** End of modified code ******************

createSearchWindowContainer();

createSearchWindowCanvas();
Expand Down Expand Up @@ -793,4 +820,4 @@ class FilterInfo {
dict["color"] = color
return dict
}
}
}