Skip to content

Commit

Permalink
feat: APPS-2421 Tweak search results to boost library content over li…
Browse files Browse the repository at this point in the history
…bguides (#747)

* feat: add indices_boost

* feat: add computed vlues for Object keys and raise the level of the indices boost

* remove test in code

* feat: add indices_boost

* feat: add computed vlues for Object keys and raise the level of the indices boost

* remove test in code

* feat: check if libguides text exists in index name

---------

Co-authored-by: pghorpade <pghorpade@library.ucla.edu>
  • Loading branch information
jendiamond and pghorpade authored Oct 11, 2023
1 parent 7706e03 commit 7b6c02f
Show file tree
Hide file tree
Showing 2 changed files with 94 additions and 27 deletions.
39 changes: 34 additions & 5 deletions layouts/error.vue
Original file line number Diff line number Diff line change
Expand Up @@ -21,11 +21,31 @@
>
An error occurred
</h1>
<p>We can’t find the page you are looking for, but we're here to help. <nuxt-link to="/">Go back to home page</nuxt-link> or try these regularly visited links:</p>

{{ error }}
</h3>

<p>
We can’t find the page you are looking for, but we're here to
help. <nuxt-link to="/">
Go back to home page
</nuxt-link> or
try these regularly visited links:
</p>
<ul>
<li><a href="https://library.ucla.edu">UCLA Library Home</a></li>
<li><a href="https://library.ucla.edu/help/research-help">Research Help</a></li>
<li><a href="https://library.ucla.edu/help/services-resources/accessibility-resources">Accessibility Resources</a></li>
<li>
<a href="https://library.ucla.edu">UCLA Library Home</a>
</li>
<li>
<a
href="https://library.ucla.edu/help/research-help"
>Research Help</a>
</li>
<li>
<a
href="https://library.ucla.edu/help/services-resources/accessibility-resources"
>Accessibility Resources</a>
</li>
</ul>
</rich-text>
</main>
Expand All @@ -52,7 +72,16 @@ export default {
font-size: 248px;
font-weight: 600;
line-height: 1;
background: linear-gradient(20deg, #FD9BE0 10.99%, #E29AEE 23.02%, #C099FF 32.91%, #8BA0EF 42.44%, #0AA5FF 56.68%, #06BEF2 73.09%, #00E0E0 89.01%);
background: linear-gradient(
20deg,
#fd9be0 10.99%,
#e29aee 23.02%,
#c099ff 32.91%,
#8ba0ef 42.44%,
#0aa5ff 56.68%,
#06bef2 73.09%,
#00e0e0 89.01%
);
-webkit-background-clip: text;
-webkit-text-fill-color: transparent;
background-clip: text;
Expand Down
82 changes: 60 additions & 22 deletions plugins/data-api.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,17 @@ export default function ({ $config }, inject) {
$config.esIndex === ""
)
return
console.log("keyword:"+keyword)
console.log("keyword:" + keyword)
/*if(keyword && keyword !== "*:*") {
keyword = keyword.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"])/g, "\\$1")
keyword = keyword.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"])/g, "\\$1")
}*/
console.log("Hello from dataapi",
JSON.stringify({
from: from,
indices_boost: [
{ "`${$config.esTempIndex}`": 1.4 },
{ "`${$config.libguidesEsIndex}`": 1.3 }
],
query: {
bool: {
must: [
Expand All @@ -50,6 +54,36 @@ export default function ({ $config }, inject) {
},
})
)

// dataAlias returns:
// {
// "apps-dev-parinita-local-2023-09-12t19-40-30.171z" : {
// "aliases" : {
// "apps-dev-current-library-website" : { }
// }
// },
// "apps-dev-libguides" : {
// "aliases" : {
// "apps-dev-current-library-website" : { }
// }
// }
// }

const responseAlias = await fetch(
`${$config.esURL}/_alias/${$config.esIndex}`,
{
headers: {
Authorization: `ApiKey ${$config.esReadKey}`,
"Content-Type": "application/json",
},
}
)
const dataAlias = await responseAlias.json()

// use omputed values for object keys: indices_boost: [ { [libraryIndex]: 3.0 },{ [libguideIndex]: 1.3 }],
const libraryIndex = !Object.keys(dataAlias)[0].includes('libguides') ? Object.keys(dataAlias)[0] : Object.keys(dataAlias)[1]
const libguideIndex = Object.keys(dataAlias)[1].includes('libguides') ? Object.keys(dataAlias)[1] : Object.keys(dataAlias)[0]

const response = await fetch(
`${$config.esURL}/${$config.esIndex}/_search`,
{
Expand All @@ -60,6 +94,10 @@ export default function ({ $config }, inject) {
method: "POST",
body: JSON.stringify({
from: from,
indices_boost: [
{ [libraryIndex]: 3.0 },
{ [libguideIndex]: 1.3 }
],
query: {
bool: {
must: [
Expand Down Expand Up @@ -93,35 +131,35 @@ export default function ({ $config }, inject) {
const data = await response.json()
return data
}
function parseFilterQuerySiteSearch(queryFilters, configMapping){
function parseFilterQuerySiteSearch(queryFilters, configMapping) {
console.log("In parseFilterQuerySiteSearch")
if (!queryFilters || queryFilters.length == 0) return []
let boolQuery = []
/*
[
{
"term": {
"sectionHandle.keyword":"Powell"
}
[
{
"term": {
"sectionHandle.keyword":"Powell"
}
]
}
]
*/
*/
for (const key in queryFilters) {
// console.log(key)

if (Array.isArray(queryFilters[key]) && queryFilters[key].length > 0) {
let filterObj = { terms: {} }
let values = []
for(let value of queryFilters[key]){
for (let value of queryFilters[key]) {
const element = configMapping.find(element => element.key === value)
values.push(element && element.terms)
}
// console.log("final values",values)
filterObj.terms[key] = values.flat()
boolQuery.push(filterObj)
}
}
}
// console.log("bool query:"+JSON.stringify(boolQuery))
return boolQuery
Expand Down Expand Up @@ -153,8 +191,8 @@ export default function ({ $config }, inject) {
console.log("sort:" + sort)

/* if(keyword && keyword !== "*:*" && keyword !== "*") {
keyword = keyword.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"])/g, "\\$1")
}*/
keyword = keyword.replace(/([\!\*\+\&\|\(\)\[\]\{\}\^\~\?\:\"])/g, "\\$1")
}*/

let testquery = JSON.stringify({
_source: [...source],
Expand Down Expand Up @@ -325,16 +363,16 @@ export default function ({ $config }, inject) {
if (!filters || filters.length == 0) return []
let boolQuery = []
/*
[
{
"term": {
"locations.title.keyword":"Powell"
}
[
{
"term": {
"locations.title.keyword":"Powell"
}
]
}
]
*/
*/
for (const key in filters) {
// console.log(key)
if (Array.isArray(filters[key]) && filters[key].length > 0) {
Expand Down

20 comments on commit 7b6c02f

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@github-actions
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.