Search test + v3 (#731)

* search patch for accurate loader/gv filtering

* backup

* basic search test

* finished test

* incomplete commit; backing up

* Working multipat reroute backup

* working rough draft v3

* most tests passing

* works

* search v2 conversion

* added some tags.rs v2 conversions

* Worked through warnings, unwraps, prints

* refactors

* new search test

* version files changes fixes

* redesign to revs

* removed old caches

* removed games

* fmt clippy

* merge conflicts

* fmt, prepare

* moved v2 routes over to v3

* fixes; tests passing

* project type changes

* moved files over

* fmt, clippy, prepare, etc

* loaders to loader_fields, added tests

* fmt, clippy, prepare

* fixed sorting bug

* reversed back- wrong order for consistency

* fmt; clippy; prepare

---------

Co-authored-by: Jai A <jaiagr+gpg@pm.me>
This commit is contained in:
Wyatt Verchere
2023-11-11 16:40:10 -08:00
committed by GitHub
parent 97ccb7df94
commit ae1c5342f2
133 changed files with 18153 additions and 11320 deletions

View File

@@ -32,11 +32,14 @@ const MEILISEARCH_CHUNK_SIZE: usize = 10000;
pub async fn index_projects(pool: PgPool, config: &SearchConfig) -> Result<(), IndexingError> {
let mut docs_to_add: Vec<UploadSearchProject> = vec![];
let mut additional_fields: Vec<String> = vec![];
docs_to_add.append(&mut index_local(pool.clone()).await?);
let (mut uploads, mut loader_fields) = index_local(pool.clone()).await?;
docs_to_add.append(&mut uploads);
additional_fields.append(&mut loader_fields);
// Write Indices
add_projects(docs_to_add, config).await?;
add_projects(docs_to_add, additional_fields, config).await?;
Ok(())
}
@@ -69,7 +72,7 @@ async fn create_index(
},
)) => {
// Only create index and set settings if the index doesn't already exist
let task = client.create_index(name, Some("project_id")).await?;
let task = client.create_index(name, Some("version_id")).await?;
let task = task.wait_for_completion(client, None, None).await?;
let index = task
.try_make_index(client)
@@ -103,7 +106,7 @@ async fn add_to_index(
) -> Result<(), IndexingError> {
for chunk in mods.chunks(MEILISEARCH_CHUNK_SIZE) {
index
.add_documents(chunk, Some("project_id"))
.add_documents(chunk, Some("version_id"))
.await?
.wait_for_completion(client, None, None)
.await?;
@@ -114,25 +117,35 @@ async fn add_to_index(
async fn create_and_add_to_index(
client: &Client,
projects: &[UploadSearchProject],
additional_fields: &[String],
name: &'static str,
custom_rules: Option<&'static [&'static str]>,
) -> Result<(), IndexingError> {
let index = create_index(client, name, custom_rules).await?;
let mut new_filterable_attributes = index.get_filterable_attributes().await?;
new_filterable_attributes.extend(additional_fields.iter().map(|s| s.to_string()));
index
.set_filterable_attributes(new_filterable_attributes)
.await?;
add_to_index(client, index, projects).await?;
Ok(())
}
pub async fn add_projects(
projects: Vec<UploadSearchProject>,
additional_fields: Vec<String>,
config: &SearchConfig,
) -> Result<(), IndexingError> {
let client = config.make_client();
create_and_add_to_index(&client, &projects, "projects", None).await?;
create_and_add_to_index(&client, &projects, &additional_fields, "projects", None).await?;
create_and_add_to_index(
&client,
&projects,
&additional_fields,
"projects_filtered",
Some(&[
"sort",
@@ -150,6 +163,7 @@ pub async fn add_projects(
fn default_settings() -> Settings {
Settings::new()
.with_distinct_attribute("project_id")
.with_displayed_attributes(DEFAULT_DISPLAYED_ATTRIBUTES)
.with_searchable_attributes(DEFAULT_SEARCHABLE_ATTRIBUTES)
.with_sortable_attributes(DEFAULT_SORTABLE_ATTRIBUTES)
@@ -161,6 +175,7 @@ fn default_settings() -> Settings {
const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
"project_id",
"version_id",
"project_type",
"slug",
"author",
@@ -168,7 +183,6 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
"description",
"categories",
"display_categories",
"versions",
"downloads",
"follows",
"icon_url",
@@ -176,8 +190,6 @@ const DEFAULT_DISPLAYED_ATTRIBUTES: &[&str] = &[
"date_modified",
"latest_version",
"license",
"client_side",
"server_side",
"gallery",
"featured_gallery",
"color",
@@ -187,10 +199,7 @@ const DEFAULT_SEARCHABLE_ATTRIBUTES: &[&str] = &["title", "description", "author
const DEFAULT_ATTRIBUTES_FOR_FACETING: &[&str] = &[
"categories",
"versions",
"license",
"client_side",
"server_side",
"project_type",
"downloads",
"follows",