lemmy icon indicating copy to clipboard operation
lemmy copied to clipboard

Search post by title only.

Open Max-dc opened this issue 1 year ago • 3 comments

Requirements

  • [X] Is this a feature request? For questions or discussions use https://lemmy.ml/c/lemmy_support
  • [X] Did you check to see if this issue already exists?
  • [X] Is this only a feature request? Do not put multiple feature requests in one issue.
  • [X] Is this a backend issue? Use the lemmy-ui repo for UI / frontend issues.
  • [X] Do you agree to follow the rules in our Code of Conduct?

Is your proposal related to a problem?

In order to avoid a duplicate post on an already existing topic. I always perform a search within lemmy /search type: post, All instances, an order. all community, all creator

But the search actually dig in the body and titles... so in order to search for a specific topics it's become cumbersome..

additionally a search by Title only would make the search quicker and lighter for the system...

Describe the solution you'd like.

May-be a checkbox search in title only ?

Describe alternatives you've considered.

There is none I believe.

Additional context

No response

Max-dc avatar Apr 30 '24 09:04 Max-dc

I could see this being useful.

dessalines avatar May 04 '24 15:05 dessalines

I would like to take up this issue :)

lambeolino avatar Aug 07 '24 07:08 lambeolino

@leoseg Do you need any help to get started? Feel free to ask here or in the dev chat.

Nutomic avatar Aug 20 '24 14:08 Nutomic

If no one is working on this I can take it.

Carlos-Cabello avatar Sep 11 '24 22:09 Carlos-Cabello

Hi I actually already started working on that issue and implemented the backend part in rust but still have to do the testing I only recently came back from vacation. But there is also the frontend part to implement the checkbox and include the parameter in the query if you want to pick up that? I named my branch "4677-Search-post-by-title-only", and the query parameter is a boolean "search_title_only" in the postquery

lambeolino avatar Sep 12 '24 07:09 lambeolino

Hi @Nutomic after merging the current main into my branch I get multiple times the same error: "error[E0658]: use of unstable library feature 'lazy_cell'" during building when running the ./test.sh script . Before the merge all tests (including my new added test) run trough without errors ? Am I missing something here?

lambeolino avatar Sep 12 '24 11:09 lambeolino

You probably need to use a newer Rust version.

Nutomic avatar Sep 12 '24 12:09 Nutomic

Yes that worked, as this is only a small feature I assume a new test for the api-tests is not needed? I added a test in the src/post_view file.

lambeolino avatar Sep 12 '24 14:09 lambeolino

@leoseg will you continue working on this issue?

Carlos-Cabello avatar Sep 12 '24 17:09 Carlos-Cabello

Yes that worked, as this is only a small feature I assume a new test for the api-tests is not needed? I added a test in the src/post_view file.

I dont see any new test in your PR, did you forget to push? As the change is quite small I dont mind merging it without test, but of course better testing is always good.

Nutomic avatar Sep 13 '24 08:09 Nutomic

Yes that worked, as this is only a small feature I assume a new test for the api-tests is not needed? I added a test in the src/post_view file.

I dont see any new test in your PR, did you forget to push? As the change is quite small I dont mind merging it without test, but of course better testing is always good.

Are you referring to my PR? I see it is already approved. I did not add any tests since I did not add any actual query logic.

Carlos-Cabello avatar Sep 13 '24 14:09 Carlos-Cabello

I didnt open a pull request yet because it wasnt ready but as I already see @Carlos-Cabello already worked this out. So I guess he continue with the issue, but I think it would be good to at least add a small unit test in post_view , which checks if the query returns less results if only searching for title.

lambeolino avatar Sep 14 '24 09:09 lambeolino

My test looked like this maybe you can do something similar @Carlos-Cabello

const POST_WITH_ANOTHER_TITLE: &str  = "Another title";
#[tokio::test]
  #[serial]
  async fn post_listing_title_only() -> LemmyResult<()> {
    let pool = &build_db_pool().await?;
    let pool = &mut pool.into();
    let data = init_data(pool).await?;


    // A post which contains the search them 'Post' not in the title (but in the body)
    let new_post = PostInsertForm::builder()
    .name( POST_WITH_ANOTHER_TITLE.to_string())
    .creator_id(data.local_user_view.person.id)
    .community_id(data.inserted_community.id)
    .language_id(Some(LanguageId(47)))
        .body(Some("Post".to_string()))
    .build();

    let inserted_post = Post::create(pool, &new_post).await?;


    let read_post_listing_by_title_only = PostQuery {
      community_id: Some(data.inserted_community.id),
      local_user: None,
      search_term: Some("Post".to_string()),
      search_title_only: Some(true),
      ..data.default_post_query()
    }
    .list(&data.site, pool)
    .await?;

    let read_post_listing  = PostQuery {
      community_id: Some(data.inserted_community.id),
      local_user: None,
      search_term: Some("Post".to_string()),
      ..data.default_post_query()
    }
    .list(&data.site, pool)
    .await?;

    // Should be 4 posts when we do not search for title only
    assert_eq!(
      vec![POST_WITH_ANOTHER_TITLE, POST_BY_BOT, POST, POST_BY_BLOCKED_PERSON],
      names(&read_post_listing)
    );

    // Should be 3 posts when we search for title only
   assert_eq!(
      vec![POST_BY_BOT, POST, POST_BY_BLOCKED_PERSON],
      names(&read_post_listing_by_title_only)
    );
    Post::delete(pool, inserted_post.id).await?;
    cleanup(data, pool).await
  }

lambeolino avatar Sep 14 '24 09:09 lambeolino

@leoseg you can also add that as a PR to @Carlos-Cabello 's branch / PR.

dessalines avatar Sep 14 '24 11:09 dessalines

This issue has been implemented, we can go ahead and close it.

Carlos-Cabello avatar Sep 16 '24 08:09 Carlos-Cabello

Hi, sorry for the delay I was busy working, the issue is already merged but I implemented the unittest in post_view.rs and created a pull request: https://github.com/LemmyNet/lemmy/pull/5033

lambeolino avatar Sep 19 '24 16:09 lambeolino