Announcement Announcement Module
Collapse
No announcement yet.
FullText index works sometimes but not others. Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • FullText index works sometimes but not others.

    So I have a User with a fullName property that has @Indexed IndexType.FULLTEXT.

    @NotNull
    @Indexed(indexName = "fullName", indexType = IndexType.FULLTEXT)
    private String fullName;

    If I have names like

    Cathy Johnson
    John Doe
    Alex Lifeson
    Bill Hader
    and more.

    I have done some tests where if I type in "John*" or "John" I correctly get Cathy Johnson and John Doe. But if I use "Alex*" or "Alex" I get no results, if I type "Bill*" or "Bill" I get no results. So it looks like it works sometimes but not others.

    Here is the derived query method in my UserRepository interface

    Page<User> findByFullName(String fullName, Pageable pageable);

    Here is my code in my service calling that repo method

    Code:
    List<User> results =
                    userRepository.findByFullName(searchCriteria + "*", PageRequestHandler.getPageRequest())
                    .getContent();
    I even modified it so it didn't concatenate the "*" but always the same results as above.

    Thanks

    Mark

  • #2
    Mark,

    I'll investigate, non-determinism here sounds very wrong. Bit busy today though so might have to wait until after the weekend.

    Lasse

    Comment


    • #3
      Mark,

      I have had no luck reproducing this, but I have a test for documentation:

      Code:
      public class FullTextIndexTests {
          @Autowired
          private TeamRepositoryExtension teams;
      
          @Test
          public void shouldIndexProperly() throws Exception {
              teams.save(new Team("Los Angeles Lakers"));
              teams.save(new Team("Los Angeles Dodgers"));
              teams.save(new Team("Los Angeles Clippers"));
              teams.save(new Team("Boston Celtics"));
              teams.save(new Team("Los Angeles Kings"));
              teams.save(new Team("Brooklyn Dodgers"));
              teams.save(new Team("Los Angeles Galaxy"));
              teams.save(new Team("Charlotte Bobcats"));
      
              assertThat(find("Los"), is(equalTo(5)));
              assertThat(find("les"), is(equalTo(0)));
              assertThat(find("lOS"), is(equalTo(5)));
              assertThat(find("Dodgers"), is(equalTo(2)));
              assertThat(find("odgers"), is(equalTo(0)));
              assertThat(find("*odgers"), is(equalTo(2)));
              assertThat(find("*odg*"), is(equalTo(2)));
              assertThat(find("Dodger"), is(equalTo(0)));
              assertThat(find("Dodger?"), is(equalTo(2)));
              assertThat(find("Ang*"), is(equalTo(5)));
              assertThat(find("B*"), is(equalTo(3)));
          }
      
          private int find(String name) {
              return teams.findByName(name, new PageRequest(0, 20)).getNumberOfElements();
          }
      }
      Entity and repo look thus:

      Code:
      @NodeEntity
      public class Team {
          @GraphId
          private Long id;
      
          @Indexed(indexName = "somethingdifferent", indexType = IndexType.FULLTEXT)
          private String name;
      
          public Team() {
      
          }
      
          public Team(String name) {
              this.name = name;
          }
      }
      
      
      
      public interface TeamRepository extends GraphRepository<Team> {
      }
      
      
      
      public interface TeamRepositoryExtension extends TeamRepository {
          Page<Team> findByName(String name, Pageable pageable);
      }
      Lucene terms and wildcars are explained in more details here: http://lucene.apache.org/core/3_6_0/...sersyntax.html

      Hope that helps - if you are able to reproduce the problem with a test I can take another look.

      Regards,

      Lasse

      Comment


      • #4
        Thanks for looking into that Lasse. Your code looks exactly what I have. And your results are what I would expect to be.

        But all I can say at this point is it doesn't work on my machine.

        It is extremely difficult for me to just do a demo on that smaller portion of my entire app.

        Thanks

        Mark

        Comment

        Working...
        X