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

Advanced Search #246

Draft
wants to merge 43 commits into
base: faceted-search
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
3e65ced
Merge pull request #239 from tripal/empty-seq-fasta
almasaeed2010 Feb 18, 2019
b6f35a0
fix #237
almasaeed2010 Feb 21, 2019
a2cf1b5
Intorduce synonyms
almasaeed2010 Feb 26, 2019
daf5191
Fix missing term when no field is provided error
almasaeed2010 Feb 26, 2019
cd1fd97
Re-add test for multi field check
almasaeed2010 Feb 26, 2019
9c196ef
Support synonyms better
almasaeed2010 Feb 26, 2019
871a281
Add an API endpoint to share categories
almasaeed2010 Feb 27, 2019
4300c71
Add tests for get bundles with fields
almasaeed2010 Feb 27, 2019
0b9c977
Add searches to be retried with fuzziness enabled
almasaeed2010 Feb 27, 2019
87faf72
Merge pull request #250 from tripal/add-categories-api
almasaeed2010 Feb 27, 2019
cb4892b
Merge pull request #252 from tripal/add-retry
almasaeed2010 Feb 27, 2019
1e01dad
Add ability to retry
almasaeed2010 Feb 27, 2019
eba60c2
Fix count function
almasaeed2010 Feb 27, 2019
faa1267
A few fixes
almasaeed2010 Feb 27, 2019
cf469f1
Fix content variable
almasaeed2010 Feb 27, 2019
822f3c0
Add support for website index
almasaeed2010 Feb 27, 2019
af763c9
Add support for fields
almasaeed2010 Feb 27, 2019
c1a1e27
Fixes
almasaeed2010 Feb 27, 2019
0438673
Convert type and bundle_label to keyword types
almasaeed2010 Feb 27, 2019
ac99344
Fixes
almasaeed2010 Feb 27, 2019
6dd537f
Fix issue
almasaeed2010 Mar 1, 2019
6c1822b
Fix error
almasaeed2010 Mar 4, 2019
1754527
Fix issue with gene search
almasaeed2010 Mar 5, 2019
44ce6b0
Merge pull request #254 from tripal/fix-253
almasaeed2010 Mar 5, 2019
663921c
Apply the gene search fix in this branch as well
almasaeed2010 Mar 5, 2019
3d471f9
Fix issue #240
almasaeed2010 Mar 5, 2019
90cfed4
Fix install error
almasaeed2010 Mar 5, 2019
656652b
oops it should be an array of fields rather than a single field
almasaeed2010 Mar 5, 2019
0aa4da1
Merge pull request #255 from tripal/fix-240
almasaeed2010 Mar 5, 2019
f1521c2
Make sure index is not deleted until foreign keys are updated
almasaeed2010 Mar 5, 2019
0a2e7d8
Merge pull request #256 from tripal/backport-fix
almasaeed2010 Mar 5, 2019
ab90861
Apply fix to make sure results are displayed when search is emapty
almasaeed2010 Mar 5, 2019
39cce25
Fix links
almasaeed2010 Mar 5, 2019
dc7a34d
Fix empty op
almasaeed2010 Mar 5, 2019
598dde4
Merge pull request #257 from tripal/fix-op
almasaeed2010 Mar 5, 2019
a5a5885
Get branch up to date with cahnges in master
almasaeed2010 Mar 5, 2019
2a708f9
Fix ssr form issue
almasaeed2010 Mar 15, 2019
aed25ea
Merge pull request #260 from tripal/fix-ssr-issue
almasaeed2010 Mar 15, 2019
ce3a581
Merge branch 'master' into advanced-search
almasaeed2010 Mar 15, 2019
61144ea
Fix missing cron setup links
almasaeed2010 Mar 25, 2019
56ddbd6
Update queues.md
almasaeed2010 Mar 25, 2019
d5c1d61
Fix documentation links
almasaeed2010 Mar 25, 2019
d94aefc
Merge branch 'master' into advanced-search
almasaeed2010 Mar 25, 2019
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
16 changes: 15 additions & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,20 @@ services:
- .:/modules/tripal_elasticsearch
- ./vendor:/var/www/html/sites/all/libraries/elasticsearch-php
elasticsearch:
image: 'elasticsearch:6.5.4'
image: 'elasticsearch:6.6.1'
ports:
- "9201:9200"
volumes:
- es_data:/usr/share/elasticsearch/data
- ./synonyms:/usr/share/elasticsearch/config/analysis
kibana:
image: 'kibana:6.6.1'
ports:
- "5601:5601"
environment:
ELASTICSEARCH_URL: "http://elasticsearch:9200"
ELASTICSEARCH_HOSTS: "http://elasticsearch:9200"
SERVER_HOST: "0.0.0.0"

volumes:
es_data:
2 changes: 1 addition & 1 deletion docs/cross-site-search.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,4 +31,4 @@ to provide the url path to the block.

**Next section: [Elasticsearch Daemon](/docs/daemon.md)**

**[Return to Handbook Index](/docs)**
'**[Return to Handbook Index](README.md)**
2 changes: 1 addition & 1 deletion docs/custom-indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ For a custom index, you will need to:

**Next section: [Building Search Forms](/docs/forms.md)**

**[Return to Handbook Index](/docs)**
'**[Return to Handbook Index](README.md)**
6 changes: 5 additions & 1 deletion docs/default-indices.md
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,10 @@ Next, you'll need to activate the `Tripal Elasticsearch website search box` bloc
Tripal Elasticsearch also provides a default index for Tripal 3 entities. To activate the index, follow the same procedure
as the website nodes index above, selecting "Entities" from the dropdown list when creating the index.

# Warning!

Before running the indexer, please make sure that your content types have the correct permissions. The indexer is only allowed to access content as an anonymous user. This prevents it from indexing private content that only administrators or authenticated users should be able to access.

### Create, Update and Delete Pages

Whenever you create a new page, update existing pages or delete pages, indexing jobs will automatically
Expand All @@ -41,4 +45,4 @@ If this setup is satisfied, you can run the indexing job in the same manner as o

**Next section: [Building Custom Indices](/docs/custom-indices.md)**

**[Return to Handbook Index](/docs)**
'**[Return to Handbook Index](README.md)**
2 changes: 1 addition & 1 deletion docs/forms.md
Original file line number Diff line number Diff line change
Expand Up @@ -28,4 +28,4 @@ If you choose a `select` field type, you must provide **key|value** pairs to bui

**Next section: [Cross Site Searching](/docs/cross-site-search.md)**

**[Return to Handbook Index](/docs)**
'**[Return to Handbook Index](README.md)**
4 changes: 3 additions & 1 deletion docs/indexing.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,6 @@ For details about indexing operations, please visit [Elasticsearch's documentati
- [Building Custom Indices](custom-indices.md)


**[Return to Handbook Index](/docs)**
**Next Section: [Running Indexing Queues](queues.md)**

'**[Return to Handbook Index](README.md)**
2 changes: 1 addition & 1 deletion docs/installation.md
Original file line number Diff line number Diff line change
Expand Up @@ -57,4 +57,4 @@ After connecting a remote server, it will be displayed in the remote server heal

**Next section: [What Is Indexing?](/docs/indexing.md)**

**[Return to Handbook Index](/docs)**
'**[Return to Handbook Index](README.md)**
2 changes: 2 additions & 0 deletions docs/queues.md
Original file line number Diff line number Diff line change
Expand Up @@ -30,3 +30,5 @@ right of each cron queue. At the bottom of the page, the URL will display. The c
the URL. For example, the cron job name is `queue_elasticsearch_queue_1` in the example below:

![cron job name](../images/get-cron-name.png)

**Next Section: [Indexing](indexing.md)**
186 changes: 186 additions & 0 deletions includes/Common/BundleHelper.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
<?php

namespace ES\Common;

class BundleHelper{

/**
* Gets a list of bundles with their associated cv terms and accessions.
*
* @return array
* An array of bundles.
*/
public function getBundles() {
$query = db_query(
'SELECT tb.name AS name,
tb.label AS label,
tb.type AS type,
tb.term_id AS term_id,
tv.vocabulary AS cv_name,
tt.accession AS accession
FROM tripal_bundle tb
INNER JOIN tripal_term tt ON tb.term_id = tt.id
INNER JOIN tripal_vocab tv ON tt.vocab_id = tv.id'
);
return $query->fetchAll();
}

/**
* @param $name
*
* @return mixed
*/
public function getBundleByName($name) {
$query = db_query(
'SELECT tb.name AS name,
tb.label AS label,
tb.type AS type,
tb.term_id AS term_id,
tv.vocabulary AS cv_name,
tt.accession AS accession
FROM tripal_bundle tb
INNER JOIN tripal_term tt ON tb.term_id = tt.id
INNER JOIN tripal_vocab tv ON tt.vocab_id = tv.id
WHERE tb.name = :name',
[
':name' => $name,
]
);
return $query->fetchObject();
}

/**
* Given a term and accession, get all bundles.
*
* @param string $cv_name The vocabulary name such as NCIT.
* @param string $accession The accession such as 0000044.
*
* @return array|null
* An array of bundles. Null if no bundles exist.
*/
public function getBundleByTerm($cv_name, $accession) {
// Get the bundle
$bundles = db_query(
'SELECT tb.name AS name,
tb.label AS label,
tb.type AS type,
tb.term_id AS term_id,
tv.vocabulary AS cv_name,
tt.accession AS accession
FROM tripal_bundle tb
INNER JOIN tripal_term tt ON tb.term_id = tt.id
INNER JOIN tripal_vocab tv ON tt.vocab_id = tv.id
WHERE tv.vocabulary = :cv_name
AND tt.accession = :accession',
[
':cv_name' => $cv_name,
':accession' => $accession,
]
)->fetchAll();

if (count($bundles) === 0) {
return NULL;
}

return $bundles;
}

/**
* Given a bundle, get all available fields.
*
* @param object $bundle The bundle object as returned from the db
* (tripal_bundle table).
*
* @return array|mixed
*/
public function getFieldsByBundle($bundle) {
$fields = field_info_instances($bundle->type, $bundle->name);

// Format the results into a simple low-memory array
$formatted = [];
foreach ($fields as $field => $data) {
$formatted[] = (object) [
'id' => $data['id'],
'name' => $field,
'label' => $data['label'],
];
}

return $formatted;
}

/**
* Get a list of fields for all bundles that match the given term.
*
* @param string $cv_name The vocabulary name.
* @param string $accession The term accesstion.
*
* @return array|null
* The list of array as ['id', 'name', 'label']. Null if no bundle exists.
*/
public function getFieldsByBundleTerm($cv_name, $accession) {
$bundles = $this->getBundleByTerm($cv_name, $accession);

if (is_null($bundles)) {
return NULL;
}

// It is likely that this loop will run only once since the possibility of
// having multiple bundles matching a single term is extra rare. We have to
// do this since there is no DB constraint on the aforementioned assertion.
$fields = [];
foreach ($bundles as $bundle) {
$fields = $fields + $this->getFieldsByBundle($bundle);
}

return $fields;
}

/**
* Gets node types in the same format as bundles.
*
* @return array
* A list of node types.
*/
public function getNodeTypes() {
$node_types = db_select('node_type', 'nt')
->fields('nt', ['type', 'name'])
->execute()
->fetchAll();

$categories = [];

foreach ($node_types as $node_type) {
$categories[] = [
'name' => $node_type->type,
'label' => $node_type->name,
'type' => 'node',
'term_id' => NULL,
'cv_term' => NULL,
'accession' => NULL,
'fields' => [],
];
}

return $categories;
}

/**
* Get a list of bundles and attach fields.
*
* @return array
* A list of bundles with fields attached.
*/
public function getBundlesWithFields() {
$bundles = $this->getBundles();

$categories = [];
foreach ($bundles as $bundle) {
$fields = $this->getFieldsByBundle($bundle);
$bundle->fields = $fields;
$categories[] = $bundle;
}

return $categories;
}
}
Loading