Commit a7aa80b4 authored by Magnus Westergaard's avatar Magnus Westergaard
Browse files

DEICH-5753: Fix field phrase search. Add search syntax e2e tests.

parent 079e6ef0
......@@ -36,7 +36,7 @@ This script also supports specifying a subset of tests to run, e.g. ```./runLike
Our autocompleting input component for authorized values in Fuge seems to trigger a SEGFAULT in Cypress' built-in Electron browser when run in headless mode. If there is more than one option in the dropdown and typed input causes some options to be eliminated (e.g. "mus" is typed in the work type field, causing the option "Litteratur" to be eliminated from the dropdown list), the test runner crashes due to a SIGSEGV signal.
This issue did not exist with Cypress 4.x, but is currently an issue with Cypress 6.4.0, which uses an Electron browser based on Chromium 87. As a result, the tests require Chromium or Google Chrome installed to run headlessly for now.
This issue did not exist with Cypress 4.x, but is currently an issue with Cypress 7.1.0, which uses an Electron browser based on Chromium 89. As a result, the tests require Chromium or Google Chrome installed to run headlessly for now.
Note: the tests run fine in the Electron browser when not in headless mode (`npx cypress open`).
......
describe("Deichman.no - search", () => {
before(() => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/`)
cy.intercept("**/api/library-events?*").as("getEvents")
cy.intercept("**/api/library-services?*").as("getServices")
cy.clearSibylDb()
cy.resetKatalogDbAndIndex()
cy.importAndIndexGraphData("testdata/deichman.no/search_spec/publications.ttl", "https://katalog.deichman.no", "publication", 11)
})
it("can search using free text", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/kattekrigerne?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
})
it("uses prefix matching implicitly for the last term in free text search", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/kattekr?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
})
it("supports prefix matching with wildcards in multiple term free text search", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/pie* garry?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Garry Fotter y el camino de la piedra")
})
it("can search using specified fields", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/tittel:kattekrigerne?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
})
it("does not use prefix matching for field search", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/tittel:kattekr?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 0)
})
it("supports prefix and suffix matching using wildcards in single term field search", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/tittel:kattekr*?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/tittel:*krigerne?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
})
it("supports phrases for field search", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/tittel:"vis steinens"?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Garry Fotter og vis steinens")
})
it("supports boolean operators OR/NOT", () => {
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/garry NOT steinens?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 1)
cy.get("[data-cy=work-card-title]").eq(0).should("contain", "Garry Fotter")
cy.get("[data-cy=work-card-title]").eq(0).should("not.contain", "steinens")
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/steen OR kattekrigerne?includeWithoutItems=includeWithoutItems`)
cy.get("[data-cy=work-card-title]").should("have.length", 2)
cy.get("[data-cy=work-card-title]").eq(0).should("have.text", "Kattekrigerne slår tilbake mot hundekrigerne")
cy.get("[data-cy=work-card-title]").eq(1).should("have.text", "Garry Fotter en de weg van de steen")
})
})
\ No newline at end of file
......@@ -6,10 +6,10 @@ describe("Deichman.no - smoketest (uten innlogging)", () => {
cy.intercept("**/api/library-services?*").as("getServices")
})
it("can search for publications", () => {
it("can search for publications and check details", () => {
cy.resetKohaDb()
cy.resetKatalogDbAndIndex()
cy.importAndIndexGraphData("testdata/deichman.no/smoketest_spec/publications.ttl", "https://katalog.deichman.no", "publication", 11)
cy.importAndIndexGraphData("testdata/deichman.no/search_spec/publications.ttl", "https://katalog.deichman.no", "publication", 11)
cy.createBibliosAndItemsInKoha()
cy.visit(`${Cypress.env("DEICHMAN_NO_URL")}/sok/*`)
......
// Remove all data from sibyl db
Cypress.Commands.add("clearSibylDb", () => {
cy.exec("bash scripts/clearSibylDb.sh").its("code").should("eq", 0)
})
......@@ -19,6 +19,7 @@ import "./common_commands"
import "./commands/fuge"
import "./commands/tjenestekatalog"
import "./commands/koha"
import "./commands/sibyl"
// enable partial object/array assertions using .containsSubset()
chai.use(chaiSubset)
This diff is collapsed.
......@@ -10,7 +10,7 @@
"license": "GPL-3.0-only",
"dependencies": {
"chai-subset": "^1.6.0",
"cypress": "^6.5.0",
"cypress": "^7.2.0",
"jsonwebtoken": "^8.5.1",
"query-string": "^6.2.0",
"uuid": "^3.3.3"
......
#!/bin/bash
docker exec -i e2e-mariadb bash -c "echo -e \"DELETE FROM sibyl.index_docs;\" | mysql -u sibyl -psecret"
docker exec -i e2e-mariadb bash -c "echo -e \"DELETE FROM sibyl.index_docs; DELETE FROM sibyl.koha_cache;\" | mysql -u sibyl -psecret"
......@@ -65,7 +65,7 @@
a deich:Publication ;
deich:created "2021-01-14T01:02:03.456Z"^^xsd:dateTime ;
deich:hasMediaType mediaType:Book ;
deich:mainTitle "Garry Fotter y el camino de la piedra " ;
deich:mainTitle "Garry Fotter y el camino de la piedra" ;
deich:publicationOf <work/w005> ;
deich:language language:spa .
......@@ -73,7 +73,7 @@
a deich:Publication ;
deich:created "2021-01-14T01:02:03.456Z"^^xsd:dateTime ;
deich:hasMediaType mediaType:Book ;
deich:mainTitle "Garry Fotter og steinens vis" ;
deich:mainTitle "Garry Fotter og vis steinens" ;
deich:publicationOf <work/w005> ;
deich:language language:nob ;
deich:publicationYear "2017"^^xsd:gYear .
......
......@@ -349,21 +349,21 @@ func (pq parsedQuery) buildMustAndShouldQueries() (mustQueries, shouldQueries []
if len(pq.fieldTerms) > 0 {
var fields []string
for _, f := range pq.fieldTerms {
leadingOrTrailingWildcard := strings.HasPrefix(f.term, "*") || strings.HasSuffix(f.term, "*")
escapedTerm := common.EscapeQueryStringQuery(f.term)
if leadingOrTrailingWildcard || strings.Contains(f.term, " ") {
fields = append(fields, fmt.Sprintf("%s:'%s'", f.field, escapedTerm))
if strings.Contains(f.term, " ") {
fields = append(fields, fmt.Sprintf(`%s:"%s"`, f.field, escapedTerm))
} else {
fields = append(fields, fmt.Sprintf("%s:%s", f.field, escapedTerm))
}
}
// NOTE! not recommended for use in search boxes, as invalid syntax will cause an error to be returned
// see: https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-query-string-query.html
mustQueries = append(mustQueries, elastic.NewQueryStringQuery(strings.Join(fields, " ")).DefaultOperator("AND"))
}
// søk på eksakte fraser (i fnutter)
for _, s := range pq.verbatimePhrases {
if strings.HasSuffix(s, "*") {
quotedWithoutWildcard := fmt.Sprintf("\"%s\"", strings.TrimSuffix(s, "*"))
mustQueries = append(mustQueries, elastic.NewMultiMatchQuery(quotedWithoutWildcard, weightedFields...).Type("phrase_prefix"))
......@@ -374,7 +374,6 @@ func (pq parsedQuery) buildMustAndShouldQueries() (mustQueries, shouldQueries []
simpleQuery.Field(f)
}
mustQueries = append(mustQueries, simpleQuery)
}
}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment